Gno.land for Go Developers

Building Your App in Web3 -- Getting to Gno

5 June 2023

Manfred Touron

VP Eng., Gno.land

What is Gno?

2

Why Go?

3

Why Gno?

4

hello.gno

package demo

func Hello(name string) string {
    return "Hello " + name + "!"
}
5

incr.gno

var x int

func Incr() {
    x += 1
}
6

render.gno

func greetings(name string) string { // private
    return "Welcome, " + name + "!"
}

func Render(path string) string {
    switch {
    case path == "hello":
        return "world!"
    case strings.HasPrefix(path, "greetings/"):
        name := strings.Split(path, "/")[1] // take string after slash
        name = strings.Title(name)          // capitalize first letter
        return greetings(name)
    }
    return "404"
}
7

imports.gno

import (
    "gno.land/p/demo/avl"
    "gno.land/p/demo/dom"
)

func Render(path string) string {
    thread := dom.Plot{Name: "Hello!"}
    thread.AddPost("Foo", "foo foo foo")
    thread.AddPost("Bar", "bar bar bar")
    return thread.String()
}
8

grc20.gno

import (
    "gno.land/p/demo/grc/grc20" 
)

var Token *grc20.Token

func init() {
    minter := grc20.NewAdminToken("Foo", "FOO", 4)
    minter.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10_000*10_000)
    Token = minter.GRC20() // expose an unprivileged token
}
9

boards/post.gno

// A Post is a "thread" or a "reply" depending on context.
// A thread is a Post of a Board that holds other replies.
type Post struct {
    board       *Board
    id          PostID
    creator     std.Address
    title       string // optional
    body        string
    replies     avl.Tree // Post.id -> *Post
    repliesAll  avl.Tree // Post.id -> *Post (all replies, for top-level posts)
    reposts     avl.Tree // Board.id -> Post.id
    threadID    PostID   // original Post.id
    parentID    PostID   // parent Post.id (if reply or repost)
    repostBoard BoardID  // original Board.id (if repost)
    createdAt   time.Time
    updatedAt   time.Time
}
10

board

source: test3.gno.land/r/demo/boards:testboard
11

post

source: test3.gno.land/r/demo/boards:testboard/2
12

source code available

source: test3.gno.land/r/demo/boards/
13

source code available

source: test3.gno.land/r/demo/boards/post.gno
14

use the CLI for TDD

# install the "gno" CLI
$> git clone git@github.com:gnolang/gno.git
$> cd ./gno
$> make install_gno

# run test
$> gno test --verbose .
=== RUN   TestPackage
--- PASS: TestPackage (0.01s)
ok      ./.     0.50s
15

Why do we need smart-contracts?

16

Game of Realms

 
     ______                              ____   ____             __
    / ____/___ _____ ___  ___     ____  / __/  / __ \___  ____ _/ /___ ___  _____
   / / __/ __ `/ __ `__ \/ _ \   / __ \/ /_   / /_/ / _ \/ __ `/ / __ `__ \/ ___/
  / /_/ / /_/ / / / / / /  __/  / /_/ / __/  / _, _/  __/ /_/ / / / / / / (__  )
  \____/\__,_/_/ /_/ /_/\___/   \____/_/    /_/ |_|\___/\__,_/_/_/ /_/ /_/____/
 
 
17

Action Items

18

Thank you

Manfred Touron

VP Eng., Gno.land

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)