Skip to content

Commit

Permalink
chore: Sync with Gitbook
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwon8247 committed Apr 14, 2023
1 parent b299a25 commit 4987e66
Show file tree
Hide file tree
Showing 59 changed files with 69 additions and 3,483 deletions.
Binary file removed .gitbook/assets/17_gnokey_query.png.png
Binary file not shown.
Binary file removed .gitbook/assets/22_gnoscan.png
Binary file not shown.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Gnoland Developer Portal

Welcome to the Gnoland Developer Portal! 
Welcome to the Gnoland Developer Portal!

The purpose of this guide is to invite new developers into the world of Gnolang, a new programming language powering the Gnoland blockchain, by providing all the resources you need to become a Gnolang expert.

_(This is an early-stage, in-progress draft. Your contributions are welcome. Please take a look at the_ [_contribution guidelines_](https://github.com/onbloc/gnoland-tutorials/blob/main/CONTRIBUTION.md)_.)_

You can read the docs in [Gitbook](https://onbloc.gitbook.io/gnoland-developer-portal/) or [GitHub](https://github.com/onbloc/gnoland-tutorials).


## Table of Contents

* Introduction to Gnoland
Expand Down
2 changes: 1 addition & 1 deletion docs/building-a-realm/deploy-and-call-realms.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deploy and Call Realms

There are two methods of deploying and calling realms. 
There are two methods of deploying and calling realms.

1. With the blockchain: You can use the subcommands of [`gnokey`](../cli/gnokey.md) such as [`addpkg`](../cli/gnokey.md#subcommands), to deploy a realm to the Gnoland blockchain, and [`maketx call`](../cli/gnokey.md#call), to call available realms in the Gnoland blockchain.
2. Without a blockchain: You can use [`gno`](../cli/gno.md), which allows you to use the GnoVM without a blockchain in a local environment. This method is fast and allows you to use development patterns such as TDD. However, it does not facilitate the capability for external parties to participate in testing since it's done locally.
Expand Down
4 changes: 2 additions & 2 deletions docs/building-a-realm/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ A realm refers to a specific instance of a smart contract that can be written in

Before we dive in, let's first study the differences between realms and packages.

#### ****[**Realms**](https://github.com/gnolang/gno/tree/master/examples/gno.land/r)****
#### [**Realms**](https://github.com/gnolang/gno/tree/master/examples/gno.land/r)

* Smart contracts in Gnolang.
* Realms are stateful.
* The default import path is `gno.land/r/~~~`.
* Each realm has the capability to publicly export the function `Render(path string) string`, which performs rendering when passed a valid markdown as a parameter for the specified `path`.

#### ****[**Packages**](https://github.com/gnolang/gno/tree/master/examples/gno.land/p/demo)****
#### [**Packages**](https://github.com/gnolang/gno/tree/master/examples/gno.land/p/demo)

* A unit that contains functionalities and utilities that can be used in realms.
* Packages are stateless.
Expand Down
6 changes: 0 additions & 6 deletions docs/building-a-realm/realm-examples/first.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func ImpossibleInc() {

Let's break down the code by each segment.



```go
var myVar = 1

Expand All @@ -76,8 +74,6 @@ The code block above displays the variable & constant declaration code (and 2 fu

As a result, once the code above is executed, the `initlVar` variable with only a declared data type, but without an initial value, is assigned with a value of `1000`.



```go
func get() int {
return myVar
Expand Down Expand Up @@ -116,8 +112,6 @@ The `Dec()` function decrements the value of `myVar`. However, as it does not po

The `ImpossibleInc()` function at the end results in an error as it attempts to modify the value of the constant.



### Test Code

```go
Expand Down
16 changes: 3 additions & 13 deletions docs/building-a-realm/realm-examples/foo.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ We first import packages and realms that we'll be using in the `foo` realm. Then

> **Note:** The `admin` address will be the only address that can can mint or burn tokens.


```go
func assertIsAdmin() error {
caller := std.GetOrigCaller()
Expand All @@ -44,8 +42,6 @@ func assertIsAdmin() error {

The `assertIsAdmin()` function implements a logic to check if the caller of the admin-only function is the `admin` address. This concept is similar to the `require` or `modifer` in Solidity.



```go
func init() {
foo = grc20.NewAdminToken("Foo Token", "FOO", 4)
Expand All @@ -61,8 +57,6 @@ The `init()` function resets the package and creates the `foo` token with the fo

Then, the function mints 100 `foo` tokens to the `admin` address.



```go
func Mint(address users.AddressOrName, amount uint64) error {
if err := assertIsAdmin(); err != nil {
Expand All @@ -83,8 +77,6 @@ func Burn(address users.AddressOrName, amount uint64) error {

The `Mint` function and the `Burn` function respectively handles minting and burning of tokens. Both functions verify that the caller is the admin using the `assertIsAdmin()` function declared above.



```go
func TotalSupply() uint64 {
return foo.TotalSupply()
Expand Down Expand Up @@ -156,11 +148,11 @@ Other functions implement the specifications of ERC20 with 2 additional function

`FaucetWithoutAdmin`: Mints 200 `foo` tokens to an address (public).

`Allowance`: Returns the amount `owner`'s tokens that the `spender` can transfer on behalf of the `owner`. 
`Allowance`: Returns the amount `owner`'s tokens that the `spender` can transfer on behalf of the `owner`.

`Approve`: Grants the `spender` with the authority to send a defined amount of `caller`'s `foo` tokens on behalf of the `caller`.

TransferFrom: The `spender` sends `owner`'s tokens on behalf of the `owner`. 
TransferFrom: The `spender` sends `owner`'s tokens on behalf of the `owner`.

####

Expand Down Expand Up @@ -295,9 +287,7 @@ func assertGRC20Balance(t *testing.T, addr users.AddressOrName, expectedBal uint
}
```

> **Tip:** the `users` realm enables users to register addresses with usernames([example](https://onbloc.gitbook.io/gnoland-developer-portal/tutorials/interact-with-gnoland#register-as-a-user)) on `/r/demo/users` for simplicity and convenience. 

> **Tip:** the `users` realm enables users to register addresses with usernames([example](https://onbloc.gitbook.io/gnoland-developer-portal/tutorials/interact-with-gnoland#register-as-a-user)) on `/r/demo/users` for simplicity and convenience.
Let's assume that 3 addresses have been registered as users as the following:

Expand Down
18 changes: 3 additions & 15 deletions docs/building-a-realm/realm-examples/foo721.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ var (

```

The code imports libraries, packages, and realms that it needs for implementation. Then, it initializes two variables to define the `admin` address, set the name of the NFT as `FooNFT`, its symbol as `FNFT`.


The code imports libraries, packages, and realms that it needs for implementation. Then, it initializes two variables to define the `admin` address, set the name of the NFT as `FooNFT`, its symbol as `FNFT`.

```go
func assertIsAdmin(address std.Address) {
Expand Down Expand Up @@ -58,8 +56,6 @@ func Burn(tid grc721.TokenID) {

The functions contained in the code above ensure that only the `admin` address has access to minting and burning of tokens.



```go
func init() {
mintNNFT(admin, 10)
Expand All @@ -76,15 +72,13 @@ func mintNNFT(owner std.Address, n uint64) {

The `init` function above mints 10 NFT tokens to the admin address. You can see from the mint function that it takes the address to receive the tokens and the amount of tokens to mint as arguments.



The logic of minting an NFT is more complex compared to that of `grc20`, due to the characteristics of NFT as follows:

* All NFTs are identified by a unique uint256 `TokenID` value.
* The `ID` cannot be modified as long as the contract is functional.
* A common practice of numbering IDs is to start from 0 and increase it by 1 in sequential order.

For example, If we want to mint NFTs from a contract, we need to know the number of NFTs minted so far from the contract, and specify `TokenID` which starts minting new NFTs. 
For example, If we want to mint NFTs from a contract, we need to know the number of NFTs minted so far from the contract, and specify `TokenID` which starts minting new NFTs.

Let's assume there's an NFT contract that:

Expand All @@ -93,8 +87,6 @@ Let's assume there's an NFT contract that:

And, if we want to mint 10 NFTs, `TokenID` will be `10`\~`19`.



```go
func BalanceOf(user users.AddressOrName) uint64 {
balance, err := foo.BalanceOf(user.Resolve())
Expand Down Expand Up @@ -155,12 +147,10 @@ Other functions are defined in the grc721 specification, each with the following
* `OwnerOf`: Checks the owner address of a token, specified by its `id`.
* `IsApprovedForAll`: Checks if all tokens of the `owner` has been approved for the `operator`.
* `GetApproved`: Checks the address of the operator that's been approved of a token, specified by its `id`.
* `Approve`: Approves a token owned by the `caller` to [a ](#user-content-fn-1)[^1]user. The token is specified by its `id`.
* `Approve`: Approves a token owned by the `caller` to a user. The token is specified by its `id`.
* `SetApprovalForAll`: Approves all tokens owned by the owner to a user.
* `TransferFrom`: Transfers a token from the `from` address to the `to` address. The token is specified by its `id`.



### Test Code

```go
Expand Down Expand Up @@ -265,5 +255,3 @@ func shouldNoPanic(t *testing.T, f func()) {
f()
}
```

[^1]:
4 changes: 1 addition & 3 deletions docs/building-a-realm/realm-examples/hello.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ Functions that make changes to the state must have a subject for change, hence m

<figure><img src="../../../.gitbook/assets/gor_01_05_qrender.png" alt=""><figcaption></figcaption></figure>

This method involves seemingly fewer options compared to `gnokey maketx call` method. However, passing the argument can be quite confusing: the realm path that exposes the `Render()` function must be placed in the `--data` option, and the arguments in a new line (`\n`).


This method involves seemingly fewer options compared to `gnokey maketx call` method. However, passing the argument can be quite confusing: the realm path that exposes the `Render()` function must be placed in the `--data` option, and the arguments in a new line ().

If we return to our realm code, we can see that the other function, `Hello()`, also doesn't cause any state changes to the blockchain.

Expand Down
14 changes: 1 addition & 13 deletions docs/building-a-realm/realm-examples/realm.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

The `realm` realm provides a guide on how to import packages in a test environment (`gno`) and the production environment (`gnokey addpkg`) along with precautions to note.



First, let's write a test package:

```go
Expand Down Expand Up @@ -119,32 +117,22 @@ func TestGetPrivateVar(t *testing.T) {

<figure><img src="../../../.gitbook/assets/gor_04_02_gnodev.png" alt=""><figcaption></figcaption></figure>

We can confirm that the test has been successfully passed in the test environment using `gno`.&#x20;


We can confirm that the test has been successfully passed in the test environment using `gno`.

<figure><img src="../../../.gitbook/assets/gor_04_03_realm_addpkg.png" alt=""><figcaption></figcaption></figure>

The package gets added successfully in the production environment.



<figure><img src="../../../.gitbook/assets/gor_04_04_render_call.png" alt=""><figcaption></figcaption></figure>

Calling `Render()` and `GetPublicVar()` using the `gnokey maketx call` also works as expected.



<figure><img src="../../../.gitbook/assets/gor_04_06_call_get_private.png" alt=""><figcaption></figcaption></figure>

However, unlike the results in `gno`, we run into an issue when calling the `getPrivateVar()` function using the `gnokey maketx call` command in the production environment.



<figure><img src="../../../.gitbook/assets/gor_04_07_query_get_private.png" alt=""><figcaption></figcaption></figure>

On the other hand, calling the `getPrivateVar()` function using the `gnokey query vm/qeval` command works successfully.



> **Note:** As of testnet3, we have run into unexpected results when using access modifiers with `gno`, `maketx`, and `query`. We suspect the cause to be one of the following: GnoVM, Gnokey Query, or gno. For now, we can get around this error by changing the lowercase to the uppercase to publicly access the functions. We will update this section once we determine the cause of this phenomenon.
14 changes: 1 addition & 13 deletions docs/building-a-realm/realm-examples/types.gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ func Test(t *testing.T) {

The AVL Tree is a commonly used package, hence results in a long test case. Let us breakdown the code by segments.



```go
{
got := gTree.Size()
Expand All @@ -133,8 +131,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

`Size() int` returns the size of the AVL Tree (number of nodes).



```go
{
got := gTree.Has("a")
Expand All @@ -155,8 +151,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

`Has(key string) (has bool)` returns the existence of the node for the given key.



```go
{
_, got := gTree.Get("a")
Expand All @@ -169,8 +163,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

`Get(key string) index int, value interface{}, exists bool`) returns the index, value, and the existence of the node for the given key.



```go
{
got, _ := gTree.GetByIndex(1)
Expand All @@ -183,8 +175,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

`GetByIndex(index int) (key string, value interface{})` returns the key and the value of the node for the given index.



```go
{
gTree.Remove("A")
Expand All @@ -198,8 +188,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

`Remove(key string)` removes the node for the given key (without returning any value).



```go
{
gTree.Set("A", "A FOR ALPHA")
Expand All @@ -219,6 +207,6 @@ The AVL Tree is a commonly used package, hence results in a long test case. Let

The `printIn` function shows all nodes of the tree based on the index.

From what is seen above, nodes are ordered as the following: special characters -> numbers -> uppercase letters -> lowercase letters -> special characters.
From what is seen above, nodes are ordered as the following: special characters -> numbers -> uppercase letters -> lowercase letters -> special characters.

The order is in the ascending code value (DEC) as specified in the [ASCII](https://www.asciitable.com/asciifull.gif).
2 changes: 0 additions & 2 deletions docs/building-a-realm/testing-realms.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Writing test cases in Gnolang is similar to that of Golang, with general rules a
* The `testing` package must be imported.
* Tests must be run with the `gno test` command.



Let's write a sample code and test it.

```go
Expand Down
8 changes: 4 additions & 4 deletions docs/building-a-realm/writing-realms.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ The sample code above imports the `avl` package and the `dom` package.
In Gnolang, the distinction of access modifiers is based on the naming conventions of objects.

* Starting with an uppercase
* Can be externally which means `Public`
* Similar to `public` and `external` in Solidity
* Can be externally which means `Public`
* Similar to `public` and `external` in Solidity
* Starting with a lowercase
* Cannot be externally accessed which means `Private`
* Similar to `private` and `internal` in Solidity
* Cannot be externally accessed which means `Private`
* Similar to `private` and `internal` in Solidity
1 change: 0 additions & 1 deletion docs/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ This section lists available Gno commands.
* [tm2txsync](tm2txsync.md) - used for importing and exporting transactions from the local blockchain node storage
* [gno](gno.md) - a handy tool for developing and prototyping gno packages / realms
* [gnofaucet](gnofaucet.md) - serves as a faucet for GNOT, the native network currency

2 changes: 1 addition & 1 deletion docs/cli/common-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Below is a list of common parameters.

| Name | Description | Default |
| ------------------------- | ------------------------------------ | ---------------------------------------- |
| `home` | The home directory. | `GNO_HOME` or the user's home directory. |
| `home` | The home directory. | `GNO_HOME` or the user's home directory. |
| `remote` | The remote node URL. | `127.0.0.1:26657` |
| `quiet` | For parsing output. | `false` |
| `insecure-password-stdin` | INSECURE! Takes password from stdin. | `false` |
20 changes: 10 additions & 10 deletions docs/cli/gno.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gno (ex gnodev)
# gno

`gno` is a handy tool for developing and prototyping Gno packages and realms. You may use `gno` to use the GnoVM without an actual blockchain to build or test realms in a local environment.

Expand Down Expand Up @@ -32,13 +32,13 @@ $ gno {SUB_COMMAND}

#### **Options**

| Name | Type | Description |
| ------------ | ------------- | --------------------------------------------------------------------- |
| `verbose` | Boolean | Displays extended information. |
| Name | Type | Description |
| ------------ | ------------- | ------------------------------------------------------------------ |
| `verbose` | Boolean | Displays extended information. |
| `root-dir` | String | Clones location of github.com/gnolang/gno (gno tries to guess it). |
| `run` | String | Test name filtering pattern. |
| `timeout` | time.Duration | The maximum execution time in ns. |
| `precompile` | Boolean | Precompiles a `.gno` file to a `.go` file before testing. |
| `run` | String | Test name filtering pattern. |
| `timeout` | time.Duration | The maximum execution time in ns. |
| `precompile` | Boolean | Precompiles a `.gno` file to a `.go` file before testing. |

### `precompile`

Expand All @@ -56,7 +56,7 @@ $ gno {SUB_COMMAND}

#### **Options**

| Name | Type | Description |
| ---------- | ------- | --------------------------------------------------------------------- |
| `verbose` | Boolean | Displays extended information. |
| Name | Type | Description |
| ---------- | ------- | ------------------------------------------------------------------ |
| `verbose` | Boolean | Displays extended information. |
| `root-dir` | String | Clones location of github.com/gnolang/gno (gno tries to guess it). |
Loading

0 comments on commit 4987e66

Please sign in to comment.