Skip to content

Commit

Permalink
Improve RPC docs (#1281)
Browse files Browse the repository at this point in the history
* fix: improve rpc docs

* fix: improve docs
  • Loading branch information
fabiorigam authored Sep 13, 2024
1 parent 9627414 commit 24218aa
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions packages/rpc-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ To install the RPC proxy, use the following command:

``` bash
yarn add @vechain/sdk-rpc-proxy
rpc-proxy
```

## Usage

The RPC proxy is simple to use. To start it, run:

``` bash
rpc-proxy
npx rpc-proxy
```

By default, the proxy is configured to be used with a solo node running on your local machine. If you want to change the
default behavior, create a config.json file and pass it to the command when launching the RPC Proxy:
By default, the proxy is configured to be used with a solo node running on your local machine. There are two options if you want to change the default behavior, or use a custom configuration:
- Create a config.json file and pass it to the command when launching the RPC Proxy.
- Use CLI options.

## Configuration file

Run:

``` bash
rpc-proxy -c <json config file>
npx rpc-proxy -c <json config file>
```

Or:

``` bash
rpc-proxy --configurationFile <json config file>
npx rpc-proxy --configurationFile <json config file>
```

## CLI Options
Expand All @@ -45,68 +49,55 @@ Cli options override the configuration file.
So you can run the rpc-proxy with:

- a configuration file with the default values and override them with the cli options
- -e.g.- `rpc-proxy -p 8545 -v ...`
- -e.g.- `npx rpc-proxy -p 8545 -v ...`

- a custom configuration file and override some values with the cli options
- -e.g.- `rpc-proxy -c /path/of/custom-config.json -p 8545 -v ...`
- -e.g.- `npx rpc-proxy -c /path/of/custom-config.json -p 8545 -v ...`

### Cli options list

#### Give the configuration file

- `-c, --configurationFile <config>`: The path to the configuration file.
- -e.g.- `rpc-proxy -c /path/of/custom-config.json` OR `rpc-proxy --configurationFile custom-config.json`
- -e.g.- `npx rpc-proxy -c /path/of/custom-config.json` OR `rpc-proxy --configurationFile custom-config.json`

- `-p, --port <port>`: The port on which the proxy server will run.
- -e.g.- `rpc-proxy -p 8545` OR `rpc-proxy --port 8545`
- -e.g.- `npx rpc-proxy -p 8545` OR `rpc-proxy --port 8545`

- `-u, --url <url>`: The URL of the VeChain Thor node.
- -e.g.- `rpc-proxy -u http://testnet.vechain.org` OR `rpc-proxy --url http://testnet.vechain.org`
- -e.g.- `npx rpc-proxy -u http://testnet.vechain.org` OR `rpc-proxy --url http://testnet.vechain.org`

- `-v, --verbose`: Whether to enable verbose logging.
- -e.g.- `rpc-proxy -v` OR `rpc-proxy --verbose`
- -e.g.- `npx rpc-proxy -v` OR `rpc-proxy --verbose`

#### Give the accounts

- `-a, --accounts <accounts>`: The accounts (private keys) that the proxy server will use to sign transactions. It is a
space-separated list of private keys.
-
-e.g.- `rpc-proxy -a "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
OR `rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
- -e.g.- `npx rpc-proxy -a "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
OR `npx rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`

- `-m, --mnemonic <mnemonic>`: The mnemonic that the proxy server will use to sign transactions.
- `-mc, --mnemonicCount <mnemonicCount>`: The number of accounts to derive from the mnemonic.
- `-mi, --mnemonicInitialIndex <mnemonicInitialIndex>`: The index from which to start deriving accounts from the
mnemonic.
- -e.g.- `rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" -mc 10 -mi 1`
OR `rpc-proxy --mnemonic "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
- -e.g.- `npx rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" -mc 10 -mi 1`
OR `npx rpc-proxy --mnemonic "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
- **NOTE**: --mnemonic, --mnemonicCount, and --mnemonicInitialIndex MUST be used together.

#### Use delegation

- `-e, --enableDelegation`: Whether to enable delegation.
- `-dp, --delegatorPrivateKey <delegatorPrivateKey>`: The private key of the delegator.
- `-du, --delegatorUrl <delegatorUrl>`: The URL of the delegator.
- -e.g.- `rpc-proxy -e -dp 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
OR `rpc-proxy --enableDelegation --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
- -e.g.- `rpc-proxy -e -du https://sponsor-testnet.vechain.energy/by/...`
OR `rpc-proxy --enableDelegation --delegatorUrl https://sponsor-testnet.vechain.energy/by/...`
- -e.g.- `npx rpc-proxy -e -dp 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
OR `npx rpc-proxy --enableDelegation --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
- -e.g.- `npx rpc-proxy -e -du https://sponsor-testnet.vechain.energy/by/...`
OR `npx rpc-proxy --enableDelegation --delegatorUrl https://sponsor-testnet.vechain.energy/by/...`
- **NOTE**: --delegatorPrivateKey and --delegatorUrl are mutually exclusive.
- **NOTE**: if --enableDelegation is used, --delegatorPrivateKey OR --delegatorUrl MUST be used.

# Run as Docker Container

To run the RPC proxy as a Docker container, follow these steps:

``` bash
docker build . -t vechain-rpc-proxy
docker run -d -p 8545:8545 -v ./config.json:/app/config.json -t vechain-rpc-proxy
```

If you do not pass a config.json file, the default solo network standard configuration will be used. Make sure to
provide your desired configuration file.

## Configuration
## Configuration file

The `config.json` file is used to configure the proxy server. It contains the following fields:

Expand Down Expand Up @@ -184,4 +175,16 @@ Simple testnet configuration with a delegator private url:
},
"enableDelegation": true
}
```
```

# Run as Docker Container

To run the RPC proxy as a Docker container, follow these steps:

``` bash
docker build . -t vechain-rpc-proxy
docker run -d -p 8545:8545 -v ./config.json:/app/config.json -t vechain-rpc-proxy
```

If you do not pass a config.json file, the default solo network standard configuration will be used. Make sure to
provide your desired configuration file.

1 comment on commit 24218aa

@github-actions
Copy link

Choose a reason for hiding this comment

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

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
99.41% (4073/4097) 98.3% (1279/1301) 99.75% (807/809)
Title Tests Skipped Failures Errors Time
core 794 0 💤 0 ❌ 0 🔥 1m 30s ⏱️
network 668 0 💤 0 ❌ 0 🔥 4m 10s ⏱️
errors 42 0 💤 0 ❌ 0 🔥 13.855s ⏱️

Please sign in to comment.