Gno by Example: Basic Realms - Hello

Before we dive in, let’s first study the differences between realms and packages. A realm is a specific instance of a smart contract written in the Gnolang programming language. On the other hand, a package contains functionalities and utilities that can be used in realms.

/// gnobyexample/hello/hello.gno
package hello
func world() string {
  return "world!"
}

Our first realm will print the classic “hello world” message.


func Render() string {
  return "Hello, " + world()
}

Then, deploy the realm on our local gnoland.


$ gnokey maketx addpkg gnobyexample \
> --pkgpath "gno.land/r/gnobyexample/hello" \
> --pkgdir "gnobyexample/hello" \
> --gas-fee 1ugnot \
> --gas-wanted 1000000 \
> --broadcast true \
> --chainid "dev" \
> --remote localhost:26657
OK!
GAS WANTED: 1000000
GAS USED:   154037
$ cd gno
...

Run gnoland website on local env.


$ ./build/website
Running on http://127.0.0.1:8888

Head to http://127.0.0.1:8888/r/gnobyexample/hello to see our deployed realm!

We can also call our smart contract using maketx call option


$ gnokey maketx call gnobyexample \
> --pkgpath "gno.land/r/gnobyexample/hello" \
> --gas-fee 1ugnot \
> --gas-wanted 1000000 \
> --broadcast true \
> --chainid "dev" \
> --remote localhost:26657 --func "Render"
("Hello, world!" string)
OK!
GAS WANTED: 1000000
GAS USED:   70250