-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gfanton nebular 2024 (#57)
Signed-off-by: gfanton <[email protected]>
- Loading branch information
Showing
19 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.gno linguist-language=Go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gno/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# http://gitpod.io/#github.com/gnolang/getting-started-workshop | ||
|
||
additionalRepositories: | ||
- url: https://github.com/gfanton/gno | ||
checkoutLocation: gno | ||
|
||
tasks: | ||
- name: Gno Deps | ||
env: | ||
GNO_ROOT: '../gno' | ||
before: echo "alias gnodev='gnodev -web-remote=$(gp url 8888)'" >> $HOME/.bashrc | ||
init: make deps | ||
command: source $HOME/.bashrc | ||
|
||
ports: | ||
- name: gnoweb | ||
description: "the Gno.land web server" | ||
port: 8888 | ||
onOpen: open-preview | ||
|
||
- name: "gnodev RPC" | ||
description: "the RPC server, managed by tendermint2" | ||
port: 26657 | ||
onOpen: ignore | ||
|
||
github: | ||
prebuilds: | ||
master: true | ||
branches: true | ||
pullRequests: true | ||
pullRequestsFromForks: true | ||
addCheck: true | ||
addComment: true | ||
addBadge: true | ||
|
||
vscode: | ||
extensions: | ||
- harry-hov.gno |
29 changes: 29 additions & 0 deletions
29
presentations/2024-07-13--nebular--gfanton/01_gno/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## 01_Gno - Go, little brother | ||
|
||
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. | ||
|
||
### Package | ||
|
||
A GNO package is generally composed of: | ||
|
||
* a `gno.mod` file that describes the package and its dependencies | ||
* some `*.gno` files (and optionally some `*_test.gno` files for testing) | ||
* an optional `README.md` | ||
|
||
Explore the different files in the current package (in the same folder as this README). | ||
|
||
### Run Gno Package | ||
To execute your package, run the following command from the directory containing the package: | ||
|
||
```bash | ||
$ gno run . | ||
``` | ||
|
||
This command runs the `main()` function in the `main.gno` file, which serves as the entry point of the package. | ||
|
||
### Testing Gno Packages | ||
Run tests using the `gno test .` command. This command executes all functions prefixed with `Test` in files that are suffixed with `_test.gno`. | ||
|
||
```bash | ||
$ gno test . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/nebular24/gno |
10 changes: 10 additions & 0 deletions
10
presentations/2024-07-13--nebular--gfanton/01_gno/main.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
func Sum(a int, b int) int { | ||
return a + b | ||
} | ||
|
||
func main() { | ||
val := Sum(2, 3) | ||
println("sum of value:", val) | ||
} |
12 changes: 12 additions & 0 deletions
12
presentations/2024-07-13--nebular--gfanton/01_gno/sum_test.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestSum(t *testing.T) { | ||
const expected = 3 | ||
|
||
actual := Sum(1, 2) | ||
if actual != expected { | ||
t.Fatalf("invalid result, expecting %d got %d", expected, actual) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
presentations/2024-07-13--nebular--gfanton/02_gnodev/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## 02_Gnodev - Debuging and Rendering | ||
|
||
`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. | ||
|
||
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. | ||
|
||
### Start gnodev | ||
|
||
To start `gnodev` on a given package, simply use the command `gnodev <pkg_path>`. | ||
|
||
To start gnodev with the package located in this folder, use: | ||
```bash | ||
$ gnodev ./02_gnodev | ||
``` | ||
|
||
> You can exit `gnodev` at any time using `Ctrl+C`. | ||
### Gnoweb | ||
|
||
`gnodev` will automatically serve `gnoweb` (by default on `:8888`). | ||
|
||
> In this demo, if you are using gitpod, a browser tab will open on `gnoweb` when running `gnodev` | ||
- On a local machine you should be able to accesse `gnoweb` in your browser with http://localhost:8888. | ||
- If you are using gitpod, you can retreive `gnoweb` url by typing `gp url 8888` in your terminal session | ||
|
||
### Access Your Realm | ||
|
||
You can then access your realm by reaching `http://<gnoweb_url>/<module_path>` url. | ||
|
||
So for the realm (package) located in the same directory as this `README`, it will be: | ||
- `http://localhost:8888/r/nebular24/gnodev` in case of gnodev running locally on your machine | ||
- `$(gp url 8888)/r/nubular24/gnodev` in case of gnodev running on gitpod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/nebular24/gnodev |
33 changes: 33 additions & 0 deletions
33
presentations/2024-07-13--nebular--gfanton/02_gnodev/render.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package render | ||
|
||
var bodyPage = ` | ||
# My Gno Realm | ||
### Realms in short: | ||
* Smart contracts in Gno. | ||
* Realms are stateful. | ||
* Realms can own assets (tokens). | ||
* Realms can implement ` + "`" + `Render(path string) string` + "`" + ` | ||
to simplify dapp frontend development by allowing users to request | ||
markdown renderings from validators and full nodes without a transaction. | ||
### Path | ||
The Render function takes a path argument that can impact its behavior. In | ||
'gnoweb', this argument can be passed by adding ` + "`" + `:<path>` + "`" + ` after the URL. | ||
*Try it, go to [/r/nebular24/gnodev:page-2](/r/nebular24/gnodev:page-2)* | ||
` | ||
|
||
func Render(path string) string { | ||
view := bodyPage | ||
|
||
if path != "" { | ||
view += "---\n" | ||
view += "### " + path + "\n" | ||
} | ||
|
||
return view | ||
} |
58 changes: 58 additions & 0 deletions
58
presentations/2024-07-13--nebular--gfanton/03_gnokey/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
## Bring Your Realm to Life with Gnokey | ||
|
||
`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. | ||
|
||
### Create an Account | ||
|
||
To create an account, simply type: | ||
|
||
``` | ||
$ gnokey add mykeyname | ||
``` | ||
__Replace `mykeyname` with the desired name for your key.__ | ||
|
||
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. | ||
|
||
You can then verify that your key has been correctly added to the keybase by typing: | ||
|
||
``` | ||
$ gnokey list | ||
``` | ||
|
||
This should correctly display your newly created key. | ||
|
||
### Start gnodev | ||
|
||
As in the previous exercise, start `gnodev` target this directory by typing | ||
|
||
``` | ||
$ gnodev ./03_gnokey | ||
``` | ||
|
||
To load the `counter` package on `gno.land/r/nebular24/gnokey` | ||
|
||
`gnodev` should automatically load the key you just created. You can verify this | ||
by pressing `A` within `gnodev` to display all known accounts and their | ||
balances. | ||
|
||
In `gnodev`, your account should have been premined with enough tokens | ||
to do whatever you want. | ||
|
||
### Interact with the contract | ||
|
||
You can then interact with the realm using the `maketx call` command from gnokey | ||
|
||
``` | ||
$ gnokey maketx call \ | ||
-pkgpath "gno.land/r/nebular24/gnokey" \ | ||
-func "Inc" \ | ||
-gas-fee 1ugnot \ | ||
-gas-wanted 2000000 \ | ||
-broadcast \ | ||
-chainid "dev" \ | ||
-remote "127.0.0.1:26657" mykeyname | ||
``` | ||
__Replace `mykeyname` with your key.__ | ||
|
||
|
||
|
21 changes: 21 additions & 0 deletions
21
presentations/2024-07-13--nebular--gfanton/03_gnokey/counter.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package counter | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
var count int | ||
|
||
func Inc() { | ||
count += 1 | ||
} | ||
|
||
func Add(value int) { | ||
count += value | ||
} | ||
|
||
func Render(path string) string { | ||
view := "# My Super Counter \n" | ||
view += "* my counter is: " + strconv.Itoa(count) | ||
return view | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/nebular24/gnokey |
55 changes: 55 additions & 0 deletions
55
presentations/2024-07-13--nebular--gfanton/04_gnoland/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## 04_GnoLand - Publish Your Realm on Gno.Land | ||
|
||
`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. | ||
|
||
### Faucet Hub | ||
|
||
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`. | ||
|
||
1. Go to https://faucet.gno.land and select `Portal Loop`. | ||
2. Enter the wallet address you created in the previous section (use `gnokey list` to retrieve the key address). | ||
3. Select the faucet amount and click on `Request Drip`. | ||
|
||
Your address should now have received some tokens! | ||
|
||
You can verify your current balance by running: | ||
```bash | ||
$ gnokey query --remote https://rpc.gno.land bank/balances/<wallet_address> | ||
``` | ||
> wallet address should be in the form `g1xxxx...` | ||
This command should display the current amount of `ugnot` you possess in your wallet. | ||
|
||
### Publish | ||
|
||
Now, it's time to upload your first package. We'll upload the package inside `04_gnoland`. | ||
|
||
1. Choose a package path name. It's recommended to use your address as the namespace for your contract: | ||
* Example: `gno.land/r/g1hr3dl82edy84a5f3dmchh0due7zgwm5rnns6na/myrealm` | ||
2. Run the following command to publish the package on `gno.land`: | ||
```bash | ||
$ gnokey maketx addpkg "<MY_KEY_NAME>" \ | ||
-pkgpath "<PKG_PATH_NAME>" \ | ||
-pkgdir "<LOCAL_PKG_DIR>" \ | ||
-gas-fee 1ugnot \ | ||
-gas-wanted 10000000 \ | ||
-broadcast \ | ||
-chainid portal-loop \ | ||
-remote https://rpc.gno.land | ||
|
||
# * `MY_KEY_NAME`: the name of your key used in the gnokey section; use `gnokey list` to retrieve it. | ||
# * `LOCAL_PKG_DIR`: the local directory containing the realm (package) you want to publish. | ||
# * `PKG_PATH_NAME`: the package path name you chose in step 1. | ||
# * You will be prompted for your key password. | ||
``` | ||
3. Visit your realm on `gno.land` using the package path you chose in step 1. | ||
* Example: `https://gno.land/r/g1hr3dl82edy84a5f3dmchh0due7zgwm5rnns6na/myrealm` | ||
|
||
### BONUS: Gno Bro | ||
|
||
There are many ways to explore realms. Try running: | ||
```bash | ||
$ ssh bro.gno.cool | ||
``` | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/nebular24/guessbook |
Oops, something went wrong.