Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add gnolang/faucet #2122

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/gno-infra/gno-infra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: gno-infra
---

# Gno Infra

Welcome to the **Gno Infra** section for Gno. This section is meant for users
wanting to learn how to run their own Gno node, set up their own faucet, run
an indexer service, and more.
173 changes: 173 additions & 0 deletions docs/gno-infra/setting-up-a-faucet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
id: setting-up-a-faucet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tutorial doesn't cover:

  • gnofaucet
  • gnofaucet vs gnolang/faucet
  • different things I've noted as part of the comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the original issue, this tutorial was meant to cover setting up a faucet with gnolang/faucet, which it does.

I suggest two options:

  1. We keep the scope of this PR to cover gnolang/faucet, and open a separate issue for documenting gnofaucet. Ideally, we would have some reference docs or at least a basic README about it before I start working on it.
  2. I'm unfamiliar with the gnofaucet functionalities and codebase - understanding the details of it are a requirement for me to be able to write a high-quality tutorial. Possibly we can jump on a quick 15 min call and you can run me through the main functionalities to speed up the process, and get this done asap?

I have fixed up all of the other comments as requested, and added a section mentioning that the faucet can be extended and referenced gnofaucet as an example: d2388e7

WDYT?

cc @Kouteki

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like option 1 better - it lets us publish this PR and make incremental progress.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leohhhn

We discussed on a call that gnofaucet is most definitely in the scope of this PR, and should be added -- please add it and ping me when it's up in the PR 🙏

Copy link
Contributor Author

@leohhhn leohhhn Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly speaking, I do not remember discussing this on a call.

However, I did take about 2h to read through the code of gnofaucet and write up a section on it. Please check it out.

I've also added a mention of the Faucet Hub.

---

# Setting up a faucet for your Gno network

In this tutorial, we will cover how to run a local native currency faucet that
works seamlessly with a Gno node. Using the faucet, any address can get a hold
of testnet GNOTs.

## Prerequisites
- Git
- Go 1.21+
- Make (for running Makefiles)
- `gnoland` & `gnokey` installed
- A Gno.land keypair generated using [`gnokey`](../gno-tooling/cli/gnokey.md)

## Premining funds to an address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should drop this section completely, and not reference genesis_balances.txt anywhere -- we have adequate genesis balances commands for premining accounts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this section and added a prerequisite: 6aeb1f5


Before setting up the faucet, we need to make sure that the address will be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a correct English sentence:

we need to make sure that the address will be used to serve the funds contain enough testnet funds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section was completely removed as per #2122 (comment)

to serve the funds contain enough testnet funds.

In your monorepo clone, visit the `genesis_balances.txt` file in the
`gno.land/genesis` folder. This file contains a list of addresses and their
initial balances upon chain initialization. The file follows the pattern below
for premining specific amounts of GNOT to an address.

```
g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5=10000000000000ugnot # test1
g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj=10000000000000ugnot # test2
```

Add the address you plan to use for your faucet in the same format:

```
<address>=<amount>ugnot
```

After this, you can spin up your chain and run the following command to check
that the address indeed contains the intended balances:

```bash
gnokey query bank/balances/<address> --remote <node_rpc_listener_address>
```

Running this command will output something like the following:

```bash
height: 0
data: "10000000000000ugnot"
```

Now this address is ready to be used for the faucet.

## Cloning the repo

To get started with setting up the faucet, visit the
[faucet repo](https://github.com/gnolang/faucet) and clone it:

```bash
git clone [email protected]:gnolang/faucet.git
```

After going into the cloned folder, you can build out the faucet binary:
```bash
make build
```

We are now ready to configure & run the faucet.

## Configuring the faucet

By running the `generate` command from the faucet binary, you will be able to generate
a `config.toml` file.

```bash
./build/faucet generate
```

In the `config.toml` file, you will be able to configure a few parameters:
- ChainID of the node to connect to
- Faucet listener address
- Mnemonic phrase to use for generating the account(s) to serve funds from
- The number of accounts to generate from the mnemonic
- The maximum drip amount for the faucet
- CORS configuration of the faucet

The default config file looks like this:
```yaml
chain_id = "dev"
listen_address = "0.0.0.0:8545"
mnemonic = "<your_mnemonic_phrase>"
num_accounts = 1
send_amount = "1000000ugnot"

[cors_config]
cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"]
cors_allowed_methods = ["HEAD", "GET", "POST", "OPTIONS"]
cors_allowed_origins = ["*"]
```

After inputting the mnemonic phrase from which your faucet address is derived
from, you are ready to run the faucet.

## Running the faucet

To run the faucet, simply run the following command:

```bash
> ./build/faucet serve --faucet-config <path_to_config.toml>

time=2024-05-16T11:25:36.012+02:00 level=INFO msg="faucet started at [::]:8545"
```

The faucet should be running on `localhost:8545`, and is connected to the locally
running `gnoland` instance. By default, `gnoland`'s rpc listener address is matched
in the `--remote` flag in the faucet. If your node is listening on a separate
address, make sure to match it accordingly when running the faucet.

## Making faucet requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling was not covered in this section, please cover it 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added possible errors a user can have while setting up the faucet or when making requests:
e33f6e3


The faucet takes in standard HTTP post requests with JSON data. The basic request
format is the following:

```json
{
"To": "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outdated, please reference the latest gnolang/faucet request structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A request without an Amount specified is actually still valid, however I have added further explanations on the amount field and how to use it: e33f6e3

}
```

You can test this out buy running the following `curl` command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here, buy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, fixed it: 15028c7

```bash
curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data '{"To": "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"}'
```

If the request is successful, you should get an output similar to the following:
```bash
{"result":"successfully executed faucet transfer"}
```

The faucet also supports batch requests, so a request such as the following is
also valid:

```json
[
{
"To": "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"
},
{
"To": "g1zzqd6phlfx0a809vhmykg5c6m44ap9756s7cjj"
}
]
```

Sending this to the faucet will receive the following response:

```json
[
{
"result": "successfully executed faucet transfer"
},
{
"result": "successfully executed faucet transfer"
}
]
```

## Conclusion

That's it 🎉

You have successfully set up a GNOT faucet on for a local Gno.land chain!
Read more about the faucet on the [`faucet`](https://github.com/gnolang/faucet) repo.
46 changes: 46 additions & 0 deletions docs/gno-tooling/cli/faucet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
id: gno-tooling-tm2-faucet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the use of this file is, it can become outdated very quickly (help output)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it: fbb91ed

---

# TM2 Faucet

TM2 Faucet is a versatile command-line interface (CLI) tool designed to
effortlessly deploy a faucet server for Gno Tendermint 2 networks. The tool can
be found on the [`gnolang/faucet`](https://github.com/gnolang/faucet) repo.

## Run `faucet` Commands

### `generate`

Generates a `config.toml` file for the faucet.

-output-path ./config.toml the path to output the TOML configuration file

#### **Options**

| Name | Type | Description |
|---------------|---------|------------------------------------------------|
| `output-path` | String | The path to output the TOML configuration file |

### `serve`

Starts the faucet with the default or given config.

```bash
faucet serve
```

#### **Options**

| Name | Type | Description |
|------------------|--------|------------------------------------------------------------------|
| `chain-id` | String | The id of the chain (required). |
| `config` | String | the path to the command configuration file [TOML] |
| `faucet-config` | String | the path to the faucet TOML configuration, if any |
| `gas-fee` | String | he static gas fee for the transaction. Format: <AMOUNT>ugnot |
| `gas-wanted` | String | the static gas wanted for the transaction. Format: <AMOUNT>ugnot |
| `listen-address` | String | the IP:PORT URL for the faucet server |
| `mnemonic` | String | the mnemonic for faucet keys |
| `num-accounts` | String | the number of faucet accounts, based on the mnemonic |
| `remote` | String | the JSON-RPC URL of the Gno chain |
| `send-amount` | String | the static max send amount per drip (native currency) |
100 changes: 0 additions & 100 deletions docs/gno-tooling/cli/faucet/faucet.md

This file was deleted.

61 changes: 0 additions & 61 deletions docs/gno-tooling/cli/faucet/gnofaucet.md

This file was deleted.