Skip to content

Commit c199cc8

Browse files
authored
feat: add gfanton nebular 2024 (#57)
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
1 parent 4502fe3 commit c199cc8

File tree

19 files changed

+477
-0
lines changed

19 files changed

+477
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.gno linguist-language=Go
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gno/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# http://gitpod.io/#github.com/gnolang/getting-started-workshop
2+
3+
additionalRepositories:
4+
- url: https://github.com/gfanton/gno
5+
checkoutLocation: gno
6+
7+
tasks:
8+
- name: Gno Deps
9+
env:
10+
GNO_ROOT: '../gno'
11+
before: echo "alias gnodev='gnodev -web-remote=$(gp url 8888)'" >> $HOME/.bashrc
12+
init: make deps
13+
command: source $HOME/.bashrc
14+
15+
ports:
16+
- name: gnoweb
17+
description: "the Gno.land web server"
18+
port: 8888
19+
onOpen: open-preview
20+
21+
- name: "gnodev RPC"
22+
description: "the RPC server, managed by tendermint2"
23+
port: 26657
24+
onOpen: ignore
25+
26+
github:
27+
prebuilds:
28+
master: true
29+
branches: true
30+
pullRequests: true
31+
pullRequestsFromForks: true
32+
addCheck: true
33+
addComment: true
34+
addBadge: true
35+
36+
vscode:
37+
extensions:
38+
- harry-hov.gno
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 01_Gno - Go, little brother
2+
3+
In this section, you will learn to use the `gno` CLI to run and test Gno packages. This part does not rely on a blockchain; instead, it operates solely on the GnoVM.
4+
5+
### Package
6+
7+
A GNO package is generally composed of:
8+
9+
* a `gno.mod` file that describes the package and its dependencies
10+
* some `*.gno` files (and optionally some `*_test.gno` files for testing)
11+
* an optional `README.md`
12+
13+
Explore the different files in the current package (in the same folder as this README).
14+
15+
### Run Gno Package
16+
To execute your package, run the following command from the directory containing the package:
17+
18+
```bash
19+
$ gno run .
20+
```
21+
22+
This command runs the `main()` function in the `main.gno` file, which serves as the entry point of the package.
23+
24+
### Testing Gno Packages
25+
Run tests using the `gno test .` command. This command executes all functions prefixed with `Test` in files that are suffixed with `_test.gno`.
26+
27+
```bash
28+
$ gno test .
29+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module gno.land/r/nebular24/gno
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
func Sum(a int, b int) int {
4+
return a + b
5+
}
6+
7+
func main() {
8+
val := Sum(2, 3)
9+
println("sum of value:", val)
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestSum(t *testing.T) {
6+
const expected = 3
7+
8+
actual := Sum(1, 2)
9+
if actual != expected {
10+
t.Fatalf("invalid result, expecting %d got %d", expected, actual)
11+
}
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 02_Gnodev - Debuging and Rendering
2+
3+
`gnodev` is a Gno development tool to works on the Gno package. It embeds a fully functional `gnoland` node (blockchain), along with `gnoweb`, a web server used to explore and visualize the `gnoland` realm.
4+
5+
By watching your development directory, `gnodev` detects changes in your Gno code and reflects them in the state of the node immediately. `gnodev` also runs a local instance of `gnoweb`, allowing you to see the rendering of your Gno code instantly.
6+
7+
### Start gnodev
8+
9+
To start `gnodev` on a given package, simply use the command `gnodev <pkg_path>`.
10+
11+
To start gnodev with the package located in this folder, use:
12+
```bash
13+
$ gnodev ./02_gnodev
14+
```
15+
16+
> You can exit `gnodev` at any time using `Ctrl+C`.
17+
18+
### Gnoweb
19+
20+
`gnodev` will automatically serve `gnoweb` (by default on `:8888`).
21+
22+
> In this demo, if you are using gitpod, a browser tab will open on `gnoweb` when running `gnodev`
23+
24+
- On a local machine you should be able to accesse `gnoweb` in your browser with http://localhost:8888.
25+
- If you are using gitpod, you can retreive `gnoweb` url by typing `gp url 8888` in your terminal session
26+
27+
### Access Your Realm
28+
29+
You can then access your realm by reaching `http://<gnoweb_url>/<module_path>` url.
30+
31+
So for the realm (package) located in the same directory as this `README`, it will be:
32+
- `http://localhost:8888/r/nebular24/gnodev` in case of gnodev running locally on your machine
33+
- `$(gp url 8888)/r/nubular24/gnodev` in case of gnodev running on gitpod
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module gno.land/r/nebular24/gnodev
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package render
2+
3+
var bodyPage = `
4+
# My Gno Realm
5+
6+
### Realms in short:
7+
8+
* Smart contracts in Gno.
9+
* Realms are stateful.
10+
* Realms can own assets (tokens).
11+
* Realms can implement ` + "`" + `Render(path string) string` + "`" + `
12+
to simplify dapp frontend development by allowing users to request
13+
markdown renderings from validators and full nodes without a transaction.
14+
15+
### Path
16+
17+
The Render function takes a path argument that can impact its behavior. In
18+
'gnoweb', this argument can be passed by adding ` + "`" + `:<path>` + "`" + ` after the URL.
19+
20+
*Try it, go to [/r/nebular24/gnodev:page-2](/r/nebular24/gnodev:page-2)*
21+
22+
`
23+
24+
func Render(path string) string {
25+
view := bodyPage
26+
27+
if path != "" {
28+
view += "---\n"
29+
view += "### " + path + "\n"
30+
}
31+
32+
return view
33+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Bring Your Realm to Life with Gnokey
2+
3+
`gnokey` is a command-line tool for interacting with a blockchain node. It allows you to make blockchain transactions, publish new packages, and perform various operations with a remote or local blockchain node.
4+
5+
### Create an Account
6+
7+
To create an account, simply type:
8+
9+
```
10+
$ gnokey add mykeyname
11+
```
12+
__Replace `mykeyname` with the desired name for your key.__
13+
14+
You will be prompted to enter a password to secure your key. It is strongly recommended to use a password, as using the key without one is not advisable outside of this workshop.
15+
16+
You can then verify that your key has been correctly added to the keybase by typing:
17+
18+
```
19+
$ gnokey list
20+
```
21+
22+
This should correctly display your newly created key.
23+
24+
### Start gnodev
25+
26+
As in the previous exercise, start `gnodev` target this directory by typing
27+
28+
```
29+
$ gnodev ./03_gnokey
30+
```
31+
32+
To load the `counter` package on `gno.land/r/nebular24/gnokey`
33+
34+
`gnodev` should automatically load the key you just created. You can verify this
35+
by pressing `A` within `gnodev` to display all known accounts and their
36+
balances.
37+
38+
In `gnodev`, your account should have been premined with enough tokens
39+
to do whatever you want.
40+
41+
### Interact with the contract
42+
43+
You can then interact with the realm using the `maketx call` command from gnokey
44+
45+
```
46+
$ gnokey maketx call \
47+
-pkgpath "gno.land/r/nebular24/gnokey" \
48+
-func "Inc" \
49+
-gas-fee 1ugnot \
50+
-gas-wanted 2000000 \
51+
-broadcast \
52+
-chainid "dev" \
53+
-remote "127.0.0.1:26657" mykeyname
54+
```
55+
__Replace `mykeyname` with your key.__
56+
57+
58+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package counter
2+
3+
import (
4+
"strconv"
5+
)
6+
7+
var count int
8+
9+
func Inc() {
10+
count += 1
11+
}
12+
13+
func Add(value int) {
14+
count += value
15+
}
16+
17+
func Render(path string) string {
18+
view := "# My Super Counter \n"
19+
view += "* my counter is: " + strconv.Itoa(count)
20+
return view
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module gno.land/r/nebular24/gnokey
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## 04_GnoLand - Publish Your Realm on Gno.Land
2+
3+
`Gno.Land` is the platform where you can upload your contract and make it available to the world, on-chain. When publishing on `Gno.Land`, there is no rollback or hot reload. Your contract will remain there permanently, so be cautious when choosing the package path to publish your realm.
4+
5+
### Faucet Hub
6+
7+
Unlike `gnodev`, you don't have any tokens to interact with the chain (yet). Let's get some for your key on the `Faucet Hub`.
8+
9+
1. Go to https://faucet.gno.land and select `Portal Loop`.
10+
2. Enter the wallet address you created in the previous section (use `gnokey list` to retrieve the key address).
11+
3. Select the faucet amount and click on `Request Drip`.
12+
13+
Your address should now have received some tokens!
14+
15+
You can verify your current balance by running:
16+
```bash
17+
$ gnokey query --remote https://rpc.gno.land bank/balances/<wallet_address>
18+
```
19+
> wallet address should be in the form `g1xxxx...`
20+
21+
This command should display the current amount of `ugnot` you possess in your wallet.
22+
23+
### Publish
24+
25+
Now, it's time to upload your first package. We'll upload the package inside `04_gnoland`.
26+
27+
1. Choose a package path name. It's recommended to use your address as the namespace for your contract:
28+
* Example: `gno.land/r/g1hr3dl82edy84a5f3dmchh0due7zgwm5rnns6na/myrealm`
29+
2. Run the following command to publish the package on `gno.land`:
30+
```bash
31+
$ gnokey maketx addpkg "<MY_KEY_NAME>" \
32+
-pkgpath "<PKG_PATH_NAME>" \
33+
-pkgdir "<LOCAL_PKG_DIR>" \
34+
-gas-fee 1ugnot \
35+
-gas-wanted 10000000 \
36+
-broadcast \
37+
-chainid portal-loop \
38+
-remote https://rpc.gno.land
39+
40+
# * `MY_KEY_NAME`: the name of your key used in the gnokey section; use `gnokey list` to retrieve it.
41+
# * `LOCAL_PKG_DIR`: the local directory containing the realm (package) you want to publish.
42+
# * `PKG_PATH_NAME`: the package path name you chose in step 1.
43+
# * You will be prompted for your key password.
44+
```
45+
3. Visit your realm on `gno.land` using the package path you chose in step 1.
46+
* Example: `https://gno.land/r/g1hr3dl82edy84a5f3dmchh0due7zgwm5rnns6na/myrealm`
47+
48+
### BONUS: Gno Bro
49+
50+
There are many ways to explore realms. Try running:
51+
```bash
52+
$ ssh bro.gno.cool
53+
```
54+
55+
This will bring you to a terminal-based version of `gno.land`, where you can fetch the previously published realm by typing its path. Enjoy the magic!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module gno.land/r/nebular24/guessbook

0 commit comments

Comments
 (0)