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

Improve RPC docs #1281

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Changes from all 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
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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be behaviour

Copy link
Member Author

Choose a reason for hiding this comment

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

In US english it's behavior. I see we use it a lot on other parts of the SDK. We should decide and be consistent.

- 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.