Search Apps Documentation Source Content File Folder Download Copy

README.md

4.94 Kb ยท 147 lines
  1This is a demo of Gno smart contract programming.  This document was
  2constructed by Gno onto a smart contract hosted on the data Realm
  3name ["gno.land/r/demo/boards"](https://gno.land/r/demo/boards/)
  4([github](https://github.com/gnolang/gno/tree/master/examples/gno.land/r/demo/boards)).
  5
  6
  7
  8## Build `gnokey`, create your account, and interact with Gno.
  9
 10NOTE: Where you see `-remote localhost:26657` here, that flag can be replaced
 11with `-remote gno.land:26657` if you have $GNOT on the testnet.
 12(To use the testnet, also replace `-chainid dev` with `-chainid portal-loop` .)
 13
 14### Build `gnokey` (and other tools).
 15
 16```bash
 17git clone git@github.com:gnolang/gno.git
 18cd gno/gno.land
 19make build
 20```
 21
 22### Generate a seed/mnemonic code.
 23
 24```bash
 25./build/gnokey generate
 26```
 27
 28NOTE: You can generate 24 words with any good bip39 generator.
 29
 30### Create a new account using your mnemonic.
 31
 32```bash
 33./build/gnokey add -recover KEYNAME
 34```
 35
 36NOTE: `KEYNAME` is your key identifier, and should be changed.
 37
 38### Verify that you can see your account locally.
 39
 40```bash
 41./build/gnokey list
 42```
 43
 44Take note of your `addr` which looks something like `g17sphqax3kasjptdkmuqvn740u8dhtx4kxl6ljf` .
 45You will use this as your `ACCOUNT_ADDR`.
 46
 47## Interact with the blockchain.
 48
 49### Add $GNOT for your account.
 50
 51Before starting the `gnoland` node for the first time, your new account can be given $GNOT in the node genesis.
 52Edit the file `gno.land/genesis/genesis_balances.txt` and add the following line (simlar to the others), using
 53your `ACCOUNT_ADDR` and `KEYNAME`
 54
 55`ACCOUNT_ADDR=10000000000ugnot # @KEYNAME`
 56
 57### Alternative: Run a faucet to add $GNOT.
 58
 59Instead of editing `gno.land/genesis/genesis_balances.txt`, a more general solution (with more steps)
 60is to run a local "faucet" and use the web browser to add $GNOT. (This can be done at any time.)
 61See this page: https://github.com/gnolang/gno/blob/master/contribs/gnofaucet/README.md
 62
 63
 64### Start the `gnoland` node.
 65
 66```bash
 67./build/gnoland start
 68```
 69
 70NOTE: The node already has the "boards" realm.
 71
 72Leave this running in the terminal. In a new terminal, cd to the same folder `gno/gno.land` .
 73
 74### Get your current balance, account number, and sequence number.
 75
 76```bash
 77./build/gnokey query auth/accounts/ACCOUNT_ADDR -remote localhost:26657
 78```
 79
 80### Register a board username with a smart contract call.
 81
 82The `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.
 83
 84```bash
 85./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
 86```
 87
 88Interactive documentation: https://gno.land/r/demo/users$help&func=Register
 89
 90### Create a board with a smart contract call.
 91
 92```bash
 93./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
 94```
 95
 96Interactive documentation: https://gno.land/r/demo/boards$help&func=CreateBoard
 97
 98Next, query for the permanent board ID by querying (you need this to create a new post):
 99
100```bash
101./build/gnokey query "vm/qeval" -data 'gno.land/r/demo/boards.GetBoardIDFromName("BOARDNAME")' -remote localhost:26657
102```
103
104### Create a post of a board with a smart contract call.
105
106NOTE: If a board was created successfully, your SEQUENCE_NUMBER would have increased.
107
108```bash
109./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
110```
111
112Interactive documentation: https://gno.land/r/demo/boards$help&func=CreateThread
113
114### Create a comment to a post.
115
116```bash
117./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
118```
119
120Interactive documentation: https://gno.land/r/demo/boards$help&func=CreateReply
121
122```bash
123./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:BOARDNAME/1" -remote localhost:26657
124```
125
126### Render page with optional path expression.
127
128The contents of `https://gno.land/r/demo/boards:` and `https://gno.land/r/demo/boards:gnolang` are rendered by calling
129the `Render(path string)` function like so:
130
131```bash
132./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:gnolang"
133```
134## View the board in the browser.
135
136### Start the web server.
137
138```bash
139./build/gnoweb
140```
141
142This should print something like `Running on http://127.0.0.1:8888` . Leave this running in the terminal.
143
144### View in the browser
145
146In your browser, navigate to the printed address http://127.0.0.1:8888 .
147To see you post, click on the package `/r/demo/boards` .