github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/boards/README.md (about) 1 This is a demo of Gno smart contract programming. This document was 2 constructed by Gno onto a smart contract hosted on the data Realm 3 name ["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 10 NOTE: Where you see `-remote localhost:26657` here, that flag can be replaced 11 with `-remote test3.gno.land:36657` 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 17 git clone git@github.com:gnolang/gno.git 18 cd gno/gno.land 19 make build 20 ``` 21 22 ### Generate a seed/mnemonic code. 23 24 ```bash 25 ./build/gnokey generate 26 ``` 27 28 NOTE: 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 36 NOTE: `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 44 Take note of your `addr` which looks something like `g17sphqax3kasjptdkmuqvn740u8dhtx4kxl6ljf` . 45 You will use this as your `ACCOUNT_ADDR`. 46 47 ## Interact with the blockchain. 48 49 ### Add $GNOT for your account. 50 51 Before starting the `gnoland` node for the first time, your new account can be given $GNOT in the node genesis. 52 Edit the file `gno.land/genesis/genesis_balances.txt` and add the following line (simlar to the others), using 53 your `ACCOUNT_ADDR` and `KEYNAME` 54 55 `ACCOUNT_ADDR=10000000000ugnot # @KEYNAME` 56 57 ### Alternative: Run a faucet to add $GNOT. 58 59 Instead of editing `gno.land/genesis/genesis_balances.txt`, a more general solution (with more steps) 60 is to run a local "faucet" and use the web browser to add $GNOT. (This can be done at any time.) 61 See 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 69 NOTE: The node already has the "boards" realm. 70 71 Leave 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 81 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. 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 87 Interactive 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 95 Interactive documentation: https://test3.gno.land/r/demo/boards?help&__func=CreateBoard 96 97 Next, 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 101 GetBoardIDFromName(\"BOARDNAME\")" -remote localhost:26657 102 ``` 103 104 ### Create a post of a board with a smart contract call. 105 106 NOTE: 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 112 Interactive documentation: https://test3.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 120 Interactive documentation: https://test3.gno.land/r/demo/boards?help&__func=CreateReply 121 122 ```bash 123 ./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards 124 BOARDNAME/1" -remote localhost:26657 125 ``` 126 127 ### Render page with optional path expression. 128 129 The contents of `https://gno.land/r/demo/boards:` and `https://gno.land/r/demo/boards:gnolang` are rendered by calling 130 the `Render(path string)` function like so: 131 132 ```bash 133 ./build/gnokey query "vm/qrender" -data "gno.land/r/demo/boards 134 gnolang" 135 ``` 136 ## View the board in the browser. 137 138 ### Start the web server. 139 140 ```bash 141 ./build/gnoweb 142 ``` 143 144 This should print something like `Running on http://127.0.0.1:8888` . Leave this running in the terminal. 145 146 ### View in the browser 147 148 In your browser, navigate to the printed address http://127.0.0.1:8888 . 149 To see you post, click on the package `/r/demo/boards` .