README.md

4.97 Kb ยท 146 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 test3.gno.land:26657` if you have $GNOT on the testnet.
 12(To use the testnet, also replace `-chainid dev` with `-chainid test3` .)
 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/gno.land/cmd/gnofaucet/README.md
 62
 63### Start the `gnoland` node.
 64
 65```bash
 66./build/gnoland start
 67```
 68
 69NOTE: The node already has the "boards" realm.
 70
 71Leave this running in the terminal. In a new terminal, cd to the same folder `gno/gno.land` .
 72
 73### Get your current balance, account number, and sequence number.
 74
 75```bash
 76./build/gnokey query auth/accounts/ACCOUNT_ADDR -remote localhost:26657
 77```
 78
 79### Register a board username with a smart contract call.
 80
 81The `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.
 82
 83```bash
 84./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
 85```
 86
 87Interactive documentation: https://test3.gno.land/r/demo/users?help&__func=Register
 88
 89### Create a board with a smart contract call.
 90
 91```bash
 92./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
 93```
 94
 95Interactive documentation: https://test3.gno.land/r/demo/boards?help&__func=CreateBoard
 96
 97Next, query for the permanent board ID by querying (you need this to create a new post):
 98
 99```bash
100./build/gnokey query "vm/qeval" -data 'gno.land/r/demo/boards.GetBoardIDFromName("BOARDNAME")' -remote localhost:26657
101```
102
103### Create a post of a board with a smart contract call.
104
105NOTE: If a board was created successfully, your SEQUENCE_NUMBER would have increased.
106
107```bash
108./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
109```
110
111Interactive documentation: https://test3.gno.land/r/demo/boards?help&__func=CreateThread
112
113### Create a comment to a post.
114
115```bash
116./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
117```
118
119Interactive documentation: https://test3.gno.land/r/demo/boards?help&__func=CreateReply
120
121```bash
122./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:BOARDNAME/1" -remote localhost:26657
123```
124
125### Render page with optional path expression.
126
127The contents of `https://gno.land/r/demo/boards:` and `https://gno.land/r/demo/boards:gnolang` are rendered by calling
128the `Render(path string)` function like so:
129
130```bash
131./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards:gnolang"
132```
133## View the board in the browser.
134
135### Start the web server.
136
137```bash
138./build/gnoweb
139```
140
141This should print something like `Running on http://127.0.0.1:8888` . Leave this running in the terminal.
142
143### View in the browser
144
145In your browser, navigate to the printed address http://127.0.0.1:8888 .
146To see you post, click on the package `/r/demo/boards` .