Skip to content

Commit

Permalink
fix(docs): getting started for docker and neutrond (#264)
Browse files Browse the repository at this point in the history
Co-authored-by: Shoaib Ahmed <[email protected]>
  • Loading branch information
ebuchman and hu55a1n1 authored Oct 21, 2024
1 parent 399d731 commit 16478ce
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 57 deletions.
2 changes: 1 addition & 1 deletion docker/neutrond/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import-local-accounts:
create-local-accounts: import-local-accounts
@echo "Local accounts have been created."

.PHONY: create-local-accounts import-local-accounts
.PHONY: create-local-accounts import-local-accounts
2 changes: 1 addition & 1 deletion docker/neutrond/data/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -rf /root/.neutrond/keyring-test &> /dev/null
neutrond tendermint unsafe-reset-all

# Init configuration files
neutrond init test --chain-id test-1 --overwrite
neutrond init test --chain-id testing --overwrite

# Modify default configurations
sed -i 's/keyring-backend = "os"/keyring-backend = "test"/g' /root/.neutrond/config/client.toml
Expand Down
116 changes: 91 additions & 25 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ Onwards with the installation and running our example app!
### Installation

Quartz is built in Rust (+wasm32 target). It expects to interact with a CosmWasm compatible
blockchain (eg. `neutrond`), built in Go (or run with Docker). And it requires `npm` for
building the frontend. Here we cover how to install Rust, Quartz, and CosmWasm
blockchains. You're responsible for installing Go and NPM.
blockchain (eg. `neutrond`), built in Go (or run with Docker).
It also requires a local version of `neutrond` for handling signing keys. And it requires `npm` for
building the frontend. Here we cover how to install Rust, Quartz, and Neutrond. You're responsible for installing Go and NPM (and optionally Docker).

Pre-reqs:
- Git
- Make
- Go or Docker
- Docker desktop v.4.34.3 with `host networking` enabled [here](https://docs.docker.com/engine/network/drivers/host/?uuid=67f19d61-ae59-4996-9060-01ebef9a586c%0A#docker-desktop).
- Go
- Docker
- For Mac, Docker desktop v.4.34.3 with `host networking` enabled [here](https://docs.docker.com/engine/network/drivers/host/?uuid=67f19d61-ae59-4996-9060-01ebef9a586c%0A#docker-desktop).
- NPM

#### Install Rust
Expand Down Expand Up @@ -109,22 +110,62 @@ And check that it worked:
quartz --help
```

#### Install a CosmWasm Client
#### Install Neutrond

For the local testnet, we can use `neutrond` with a single validator (we have a docker image for this).
A version of `neutrond` is required both for running a node and for managing
keys. Running the node can be done via docker, which is easier to get running,
but the Go binary will have to be installed regardless for signing transactions.

For `neutrond`:
To install the `neutrond` binary:

```bash
git clone -b main https://github.com/neutron-org/neutron.git
cd neutron
git checkout v4.0.1
make install-test-binary
```

You can now start the node either using this version of `neutrond` or using
Docker.

To use your local `neutrond` to run the node, you'll have to setup your
config and genesis files. See the [neutrond setup guide](/docs/neutrond_setup.md), and then return back here and
skip down to the bottom of this section.

Alternatively, you can start the node using docker.

If you're on Mac using Docker Desktop, make sure to enable [host networking](https://docs.docker.com/engine/network/drivers/host/?uuid=67f19d61-ae59-4996-9060-01ebef9a586c%0A#docker-desktop).

Then:

```bash
cd docker
docker compose up node
```

It will pre-configure a few keys (admin, alice, etc.) and allocate funds to them.
The default sending account for quartz txs is `admin`.
The default sending account for txs is `admin`, as specified in
`examples/transfers/quartz.toml`.

If building from source, you'll need to initialize the accounts yourself. See
the guide on [setting up a CosmWasm chain](/docs/neutrond_setup.md) and then return back here.
Finally, you'll need to import the keys from the docker container into your
local `neutrond`. From inside the `docker` dir:

```bash
tail -n 1 neutrond/data/accounts/admin.txt | neutrond keys add admin --no-backup --recover --keyring-backend=test
```

If you already have a key called `admin` in your keystore you'll have to rename it first.

If you want to use a different name then `admin`, be sure to also change it in
the `examples/transfers/quartz.toml` and everywhere we use it below.

Check that the key is there:

```bash
neutrond keys show admin
```

And you're good to go!

### Local neutrond Testnet Without SGX

Expand All @@ -139,6 +180,30 @@ We can deploy the enclave and contract all at once using the `quartz dev`
convenience command (like in the [quick start](#quick-start)), but here we'll
show the individual commands.

### Configure Key

At the moment, we have to do an insecure operation to export the private key to
be used for signing transactions so it can be used by the enclave. This is a
temporary hack.

If you're using docker, the key is hardcoded:

```bash
export ADMIN_SK=ffc4d3c9119e9e8263de08c0f6e2368ac5c2dacecfeb393f6813da7d178873d2
```

Otherwise, you can set the key like so:

```bash
export ADMIN_SK=$(yes | neutrond keys export admin --unsafe --unarmored-hex)
```

Now make sure the key is set:

```bash
echo $ADMIN_SK
```

### Enclave

First we build and run the enclave code.
Expand Down Expand Up @@ -188,11 +253,6 @@ environment variable:
export CONTRACT_ADDRESS=<CONTRACT_ADDRESS>
```

You must also set the admin secret key:

```bash
export ADMIN_SK=ffc4d3c9119e9e8263de08c0f6e2368ac5c2dacecfeb393f6813da7d178873d2
```

3. Perform the handshake:
```bash
Expand All @@ -209,11 +269,11 @@ environment variable:
export PUBKEY=<PUBKEY>
```

Now the contract is ready to start processing requests to the enclave. You will see logs from the enclave showing:
Now the contract is ready to start processing requests to the enclave!

```bash
2024-09-24T11:12:25.156779Z INFO Enclave is listening for requests...
```
The enclave process should be showing logs that it's listening for request.
There's a bug so it won't right now, and will show some error you can ignore.
Good times. Let's move on to setting up the frontend.

### Frontend

Expand All @@ -235,8 +295,10 @@ You can run the front end on your local computer, so it is easy to test in a bro
```

Now open `.env.local` and edit the values of `NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS` and
`NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY` to be the contract address and pubkey from the previous step. With quartz dev, they can be grabbed
from the logs. From the manual process, you would have already stored them as environment variables.
`NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY` to be the contract address and pubkey from the previous step.
You should have them stored as environment variables `$CONTRACT_ADDRESS` and
`$PUBKEY`. (Note if you ran `quartz dev` instead of all the manual steps you can
get them out of the logs)

4. Finally, start the frontend:
```bash
Expand All @@ -251,22 +313,26 @@ if you are just testing and you don't clear your browser storage, you will be fi

You'll need to have the Keplr wallet browser extension installed and unlocked.

You may have to go to "Manage Chain Visibility" in Keplr settings to add the `My
Testing Chain` so you can talk to your local chain and see your balance.
You may have to go to "Manage Chain Visibility" in Keplr settings to add the
`Local Neutron Testchain` so you can talk to your local chain and see your balance.

Create a new address in Keplr for testing purpose. You'll need to send this
address some funds from the `admin` account setup with your local node. For
instance, send 10M untrn with:

```bash
neutrond tx bank send admin <KEPLR ADDRESS> 10000000untrn --chain-id testing
neutrond tx bank send admin <KEPLR ADDRESS> 10000000untrn --chain-id testing --fees 10000untrn
```

You should now see the funds on your local testnet on Keplr.

Now you can interact with the app by depositing funds, privately transferring
them to other addresses, and finally withdrawing them.

If you want to test multiple addresses, create the other addresses in Keplr and
be sure to send them some `untrn` from the `admin` account so they can pay for
gas.

Be sure to check the enclave window to see the logs from your interaction with
the app!

Expand Down
72 changes: 45 additions & 27 deletions docs/neutrond_setup.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# CosmWasm Binaries: Manual Install and Configure
# Neutrond Setup

> Note - We highly recommend setting up `neutrond` with the docker image provided. However, we have provided these detailed instructions in case you wanted to take a deeper look.
> Note - We would like to highly recommend setting up the `neutrond` node with the docker image provided. However, we also understand that docker is a poison upon the human soul, and thus provide these instructions for setting up the neutrond node locally, without imbibing such poision. It will probably take less time to follow these instructions than it will to build the docker image anyways. Up to you 🫡
Quartz expects to interact with a CosmWasm-based blockchain.
The default/archetypal binary is `neutrond`. We have included instructions for `wasmd`, but it is not supported in the cli today.
The default/archetypal binary is `neutrond`. Currently its hardcoded to use
`neutrond` though of course we will make this configurable soon.

Here we describe how to get setup from scratch or how to use an existing `neutrond`
binary/network you have access to.
Expand All @@ -21,39 +22,33 @@ For `neutrond`:
```bash
git clone -b main https://github.com/neutron-org/neutron.git
cd neutron
git checkout v4.0.0
make install
```

For `wasmd` (NOTE - NOT SUPPORTED BY CLI):

```bash
git clone https://github.com/cosmwasm/wasmd/
cd wasmd
git checkout v0.45.0
go install ./cmd/wasmd
git checkout v4.0.1
make install-test-binary
```

## Configure From Scratch

We have to initialize a new chain and load it with some accounts.

We'll assume you're using `neutrond` but it could be `wasmd` or any other.
If you already have `neutrond` keys, you may need to rename them or use
different names if the names overlap.

We also have to give the chain a chain ID. We'll use `testing`.

Run

```bash
neutrond init <your name> --chain-id testing
neutrond init yourname --chain-id testing --default-denom untrn
```

to initialize the local neutrond folder.

Now open the file `~/.neutrond/config/client.toml` and change the field
`keyring-backend` from `os` to `test`:

```toml keyring-backend = "test" ```
```toml
keyring-backend = "test"
```

Now, finally, we can create a local admin key for your neutrond. You'll use this to
deploy contracts:
Expand All @@ -62,25 +57,24 @@ deploy contracts:
neutrond keys add admin
```

If you already have a key called `admin` in your keystore it's advised to rename it first.
If you want to use a different name then `admin`, be sure to also change it in
the `examples/transfers/quartz.toml` and everywhere we use it below.

This should output a neutron address.

Now create the genesis file.

```bash
# generate a second key for the validator
neutrond keys add validator

# fund both accounts in genesis
neutrond genesis add-genesis-account admin 100000000000stake,100000000000ucosm
neutrond genesis add-genesis-account validator 100000000000stake,100000000000ucosm
# fund the account in genesis
neutrond add-genesis-account admin 100000000000untrn

# sign genesis tx from validator and compose genesis
neutrond genesis gentx validator 100000000stake --chain-id testing
neutrond genesis collect-gentxs
# configure the ICS setup (neutrond expects to run as a consumer chain)
neutrond add-consumer-section
```

Before finally starting the node, for it to work with the front end, you need to
configure CORS.
configure CORS and a min gas price.

### Configure CORS

Expand All @@ -102,6 +96,30 @@ address = "tcp://0.0.0.0:1317"
enabled-unsafe-cors = true
```

### Configure min gas

In `~/.neutrond/config/app.toml`, set the min gas price:

```toml
minimum-gas-prices = "0.0001untrn"
```

And in `~/.neutrond/config/genesis.json`, set the denom and the feemarket min gas price:

```json
"fee_denom": "untrn",
```

```json
"min_base_gas_price": "0.000100000000000000",
```

and

```json
"base_gas_price": "0.000100000000000000",
```

Now, finally:

## neutrond start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainInfo } from '@keplr-wallet/types'

// Neutron local chain definition
export const localNeutron: ChainInfo = {
chainId: 'test-1',
chainId: 'testing',
chainName: 'Local Neutron Testchain',
rpc: 'http://localhost:26657',
rest: 'http://localhost:1317',
Expand Down
4 changes: 2 additions & 2 deletions examples/transfers/quartz.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mock_sgx = true
tx_sender = "admin"
chain_id = "test-1"
chain_id = "testing"
node_url = "http://127.0.0.1:26657"
ws_url = "ws://127.0.0.1:26657/websocket"
grpc_url = "http://127.0.0.1:9090"
enclave_rpc_addr = "http://127.0.0.1"
enclave_rpc_port = 11090
trusted_hash = ""
trusted_height = 0
release = true
release = true

0 comments on commit 16478ce

Please sign in to comment.