This is a demo of Gno smart contract programming. This document was constructed by Gno onto a smart contract hosted on the data Realm name "gno.land/r/demo/boards" (github).
NOTE: Where you see -remote localhost:26657
here, that flag can be replaced
with -remote gno.land:26657
if you have $GNOT on the testnet.
(To use the testnet, also replace -chainid dev
with -chainid portal-loop
.)
git clone [email protected]:gnolang/gno.git
cd gno/gno.land
make build
./build/gnokey generate
NOTE: You can generate 24 words with any good bip39 generator.
./build/gnokey add -recover KEYNAME
NOTE: KEYNAME
is your key identifier, and should be changed.
./build/gnokey list
Take note of your addr
which looks something like g17sphqax3kasjptdkmuqvn740u8dhtx4kxl6ljf
.
You will use this as your ACCOUNT_ADDR
.
Before starting the gnoland
node for the first time, your new account can be given $GNOT in the node genesis.
Edit the file gno.land/genesis/genesis_balances.txt
and add the following line (simlar to the others), using
your ACCOUNT_ADDR
and KEYNAME
ACCOUNT_ADDR=10000000000ugnot # @KEYNAME
Instead of editing gno.land/genesis/genesis_balances.txt
, a more general solution (with more steps)
is to run a local "faucet" and use the web browser to add $GNOT. (This can be done at any time.)
See this page: https://github.com/gnolang/gno/blob/master/contribs/gnofaucet/README.md
./build/gnoland start
NOTE: The node already has the "boards" realm.
Leave this running in the terminal. In a new terminal, cd to the same folder gno/gno.land
.
./build/gnokey query auth/accounts/ACCOUNT_ADDR -remote localhost:26657
The USERNAME
for posting can different than your KEYNAME
. It is internally linked to your ACCOUNT_ADDR
. It must be at least 6 characters, lowercase alphanumeric with underscore.
./build/gnokey maketx call -pkgpath "gno.land/r/demo/users" -func "Register" -args "" -args "USERNAME" -args "Profile description" -gas-fee "10000000ugnot" -gas-wanted "2000000" -send "200000000ugnot" -broadcast -chainid dev -remote 127.0.0.1:26657 KEYNAME
Interactive documentation: https://gno.land/r/demo/users?help&__func=Register
./build/gnokey maketx call -pkgpath "gno.land/r/demo/boards" -func "CreateBoard" -args "BOARDNAME" -gas-fee "1000000ugnot" -gas-wanted "10000000" -broadcast -chainid dev -remote localhost:26657 KEYNAME
Interactive documentation: https://gno.land/r/demo/boards?help&__func=CreateBoard
Next, query for the permanent board ID by querying (you need this to create a new post):
./build/gnokey query "vm/qeval" -data 'gno.land/r/demo/boards.GetBoardIDFromName("BOARDNAME")' -remote localhost:26657
NOTE: If a board was created successfully, your SEQUENCE_NUMBER would have increased.
./build/gnokey maketx call -pkgpath "gno.land/r/demo/boards" -func "CreateThread" -args BOARD_ID -args "Hello gno.land" -args "Text of the post" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid dev -remote localhost:26657 KEYNAME
Interactive documentation: https://gno.land/r/demo/boards?help&__func=CreateThread
./build/gnokey maketx call -pkgpath "gno.land/r/demo/boards" -func "CreateReply" -args BOARD_ID -args "1" -args "1" -args "Nice to meet you too." -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid dev -remote localhost:26657 KEYNAME
Interactive documentation: https://gno.land/r/demo/boards?help&__func=CreateReply
./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:BOARDNAME/1" -remote localhost:26657
The contents of https://gno.land/r/demo/boards:
and https://gno.land/r/demo/boards:gnolang
are rendered by calling
the Render(path string)
function like so:
./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:gnolang"
./build/gnoweb
This should print something like Running on http://127.0.0.1:8888
. Leave this running in the terminal.
In your browser, navigate to the printed address http://127.0.0.1:8888 .
To see you post, click on the package /r/demo/boards
.