Skip to content

Commit 7aac486

Browse files
authored
Update RPC Docs (#1893)
* chore: docker ci * fix: hardcode * chore: fix * chore: update readme * chore: typo
1 parent a3db82f commit 7aac486

File tree

4 files changed

+123
-93
lines changed

4 files changed

+123
-93
lines changed

.github/workflows/publish-sdk.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Publish NPM package
22

33
on:
4-
workflow_call:
4+
workflow_dispatch:
55

66
permissions:
77
contents: read

.github/workflows/rpc-proxy-docker.yml

+17-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ name: RPC Proxy - Docker build, scan and push
33
on:
44
workflow_call:
55

6+
env:
7+
DOCKERFILE_LOCATION: "docker/rpc-proxy/Dockerfile"
8+
DOCKER_IMAGE_NAME: "vechain/sdk-rpc-proxy"
9+
DOCKER_IMAGE_VERSION: "v1.0.0"
10+
611
permissions:
712
contents: read
813
packages: write
914
checks: write
1015
actions: read
1116

17+
1218
jobs:
1319
docker:
1420
runs-on: ubuntu-latest
@@ -31,20 +37,19 @@ jobs:
3137
username: ${{ secrets.DOCKERHUB_USERNAME }}
3238
password: ${{ secrets.DOCKERHUB_TOKEN }}
3339

34-
- name: Extract metadata (tags, labels) for Docker
35-
id: meta
36-
uses: docker/metadata-action@v5
37-
with:
38-
images: vechain/sdk-rpc-proxy
39-
4040
- name: Build and export to Docker
4141
uses: docker/build-push-action@v6
4242
with:
4343
context: .
44-
file: docker/rpc-proxy/Dockerfile
44+
file: ${{ env.DOCKERFILE_LOCATION }}
4545
load: true
46-
tags: ${{ steps.meta.outputs.tags }}
47-
labels: ${{ steps.meta.outputs.labels }}
46+
tags: "${{ env.DOCKER_IMAGE_NAME }}:${{env.DOCKER_IMAGE_VERSION}}"
47+
labels: |
48+
maintainer=vechain
49+
description="RPC Proxy for vechain Thor"
50+
build_timestamp=${{ github.event.after }}
51+
source=https://github.com/vechain/vechain-sdk-js
52+
commit_hash=${{ github.sha }}
4853
4954
- name: Create .trivyignore file
5055
# "cross-spawn" is resolved as version 7.0.5 but Trivy keeps showing the error
@@ -55,7 +60,7 @@ jobs:
5560
- name: Run Trivy Scan
5661
uses: aquasecurity/trivy-action@master
5762
with:
58-
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
63+
image-ref: ${{env.DOCKER_IMAGE_NAME}}
5964
format: 'table'
6065
ignore-unfixed: true
6166
exit-code: '1'
@@ -72,8 +77,7 @@ jobs:
7277
uses: docker/build-push-action@v6
7378
with:
7479
context: .
75-
file: docker/rpc-proxy/Dockerfile
80+
file: ${{env.DOCKERFILE_LOCATION}}
7681
platforms: linux/amd64,linux/arm64
7782
push: true
78-
tags: ${{ steps.meta.outputs.tags }}
79-
labels: ${{ steps.meta.outputs.labels }}
83+
tags: "${{ env.DOCKER_IMAGE_NAME }}:${{env.DOCKER_IMAGE_VERSION}}"

.github/workflows/rpc-proxy.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: RPC Proxy
22

33
on:
4-
workflow_call:
4+
workflow_dispatch:
55

66
jobs:
77
test:
8-
if: github.ref != 'refs/tags/*'
98
uses: ./.github/workflows/rpc-proxy-test.yml
109
secrets: inherit
1110

packages/rpc-proxy/README.md

+104-77
Original file line numberDiff line numberDiff line change
@@ -8,108 +8,150 @@ The RPC Proxy is designed to bridge the gap between Thor's RESTful API and Ether
88
interaction with the VeChainThor blockchain through RPC calls. It is particularly useful for integrating with tools such
99
as the Remix IDE.
1010

11-
## Installation
11+
The RPC Proxy can be optionally configured to:
1212

13-
To install the RPC proxy, use the following command:
13+
* sign transactions for `eth_signTransaction` RPC method
14+
* use a vechain account for fee delegation
15+
16+
## Useage
17+
18+
The RPC proxy can be used in two different ways:
19+
20+
* Executing directly via node package execute (npx)
21+
* Executing via Docker container
22+
23+
Both ways of using can be configured via a configuration file or using command line options
24+
25+
## Starting the Proxy
26+
27+
To install the RPC proxy for NPX useage, use the following command:
1428

1529
``` bash
1630
yarn add @vechain/sdk-rpc-proxy
1731
```
1832

19-
## Usage
20-
21-
The RPC proxy is simple to use. To start it, run:
33+
To start the proxy, run:
2234

2335
``` bash
2436
npx rpc-proxy
2537
```
2638

27-
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:
28-
- Create a config.json file and pass it to the command when launching the RPC Proxy.
29-
- Use CLI options.
30-
31-
## Configuration file
32-
33-
Run:
39+
To start the proxy with Docker:
3440

3541
``` bash
36-
npx rpc-proxy -c <json config file>
42+
docker run -d -p 8545:8545 -t vechain/sdk-rpc-proxy:<tag>
3743
```
3844

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

41-
``` bash
42-
npx rpc-proxy --configurationFile <json config file>
43-
```
4450

4551
## CLI Options
4652

47-
With rpc-proxy, you can use the following CLI options.
48-
Cli options override the configuration file.
49-
So you can run the rpc-proxy with:
53+
The following CLI options exist.
54+
CLI options override any used configuration file.
5055

51-
- a configuration file with the default values and override them with the cli options
52-
- -e.g.- `npx rpc-proxy -p 8545 -v ...`
56+
| NPX CLI Option | Description |
57+
|-----------------------------------------|---------------------------------------------------------|
58+
| -p (--port) <number> | port number for the service |
59+
| -c (--configurationFile) <filepath> | path to configuration file |
60+
| -u (--url) <url> | url to vechain thor node |
61+
| -v (--verbose) | to turn on verbose logging |
62+
| -a (--accounts) <keys> | the private keys used to sign tx's |
63+
| -m (--mnemonic) <mnemonic> | mnemonic to derive private keys to sign tx's with |
64+
| -mc (--mnemonicCount) <number> | the number of accounts to derive from the mnemonic |
65+
| -mi (--mnemonicInitialIndex) <number> | index to start deriving accounts from the mnemonic |
66+
| -e (--enableDelegation) | turns on fee delegation for signed tx's |
67+
| --gasPayerPrivateKey <key> | private key of the gas payer |
68+
| -s (--gasPayerServiceUrl) <url> | fee delegation service url |
5369

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

57-
### Cli options list
71+
For docker based execution, CLI options are passed as environment variables.
5872

59-
#### Give the configuration file
6073

61-
- `-c, --configurationFile <config>`: The path to the configuration file.
62-
- -e.g.- `npx rpc-proxy -c /path/of/custom-config.json` OR `rpc-proxy --configurationFile custom-config.json`
74+
| Docker ENV Variable | Description |
75+
|-----------------------------------------|---------------------------------------------------------|
76+
| URL | url to vechain thor node |
77+
| PORT | internal port number for the service |
78+
| ACCOUNTS | private keys to sign transactions |
79+
| MNEMONIC | mnemonic to derive private keys to sign tx's with |
80+
| MNEMONIC_COUNT | the number of accounts to derive from the mnemonic |
81+
| MNEMONIC_INITIAL_INDEX | index to start deriving accounts from the mnemonic |
82+
| ENABLE_DELEGATION | turns on fee delegation for signed tx's |
83+
| GAS_PAYER_PRIVATE_KEY | private key of the gas payer |
84+
| GAS_PAYER_SERVICE_URL | fee delegation service url |
85+
| CONFIGURATION_FILE | path to configuration file |
6386

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

67-
- `-u, --url <url>`: The URL of the VeChainThor node.
68-
- -e.g.- `npx rpc-proxy -u http://testnet.vechain.org` OR `rpc-proxy --url http://testnet.vechain.org`
88+
#### NPX CLI Examples:
6989

70-
- `-v, --verbose`: Whether to enable verbose logging.
71-
- -e.g.- `npx rpc-proxy -v` OR `rpc-proxy --verbose`
90+
- passing configuration file and port:
91+
- `npx rpc-proxy -c /path/of/custom-config.json -p 8545 -v ...`
7292

73-
#### Give the accounts
93+
- passing url of vechain thor node:
94+
- `npx rpc-proxy -u http://testnet.vechain.org` OR `rpc-proxy --url http://testnet.vechain.org`
7495

75-
- `-a, --accounts <accounts>`: The accounts (private keys) that the proxy server will use to sign transactions. It is a
76-
space-separated list of private keys.
77-
- -e.g.- `npx rpc-proxy -a "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
78-
OR `npx rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
96+
- enabling verbose logging:
97+
- `npx rpc-proxy -v` OR `rpc-proxy --verbose`
7998

80-
- `-m, --mnemonic <mnemonic>`: The mnemonic that the proxy server will use to sign transactions.
81-
- `-mc, --mnemonicCount <mnemonicCount>`: The number of accounts to derive from the mnemonic.
82-
- `-mi, --mnemonicInitialIndex <mnemonicInitialIndex>`: The index from which to start deriving accounts from the
83-
mnemonic.
84-
- -e.g.- `npx rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" -mc 10 -mi 1`
85-
OR `npx rpc-proxy --mnemonic "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
86-
- **NOTE**: --mnemonic, --mnemonicCount, and --mnemonicInitialIndex MUST be used together.
99+
- specificying the accounts (private keys) to sign transactions. It is a space-separated list of private keys.
100+
- `npx rpc-proxy -a "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
101+
- `npx rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`
87102

88-
#### Use delegation
103+
- specifying the mnemonic to derive tx signing accounts from:
104+
- `npx rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" -mc 10 -mi 1`
105+
- `npx rpc-proxy --mnemonic "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
106+
- **NOTE**: --mnemonic, --mnemonicCount, and --mnemonicInitialIndex MUST be used together.
89107

90-
- `-e, --enableDelegation`: Whether to enable delegation.
91-
- `--gasPayerPrivateKey <gasPayerPrivateKey>`: The private key of the gasPayer.
92-
- `-s, --gasPayerServiceUrl <gasPayerServiceUrl>`: The URL of the gasPayer.
93-
- -e.g.- `npx rpc-proxy -e --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
94-
OR `npx rpc-proxy --enableDelegation --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
95-
- -e.g.- `npx rpc-proxy -e -s https://sponsor-testnet.vechain.energy/by/...`
96-
OR `npx rpc-proxy --enableDelegation --gasPayerServiceUrl https://sponsor-testnet.vechain.energy/by/...`
108+
- enabling fee delegation:
109+
- `npx rpc-proxy -e -gk 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
110+
- `npx rpc-proxy --enableDelegation --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
111+
- `npx rpc-proxy -e -s https://sponsor-testnet.vechain.energy/by/...`
112+
- `npx rpc-proxy --enableDelegation --gasPayerServiceUrl https://sponsor-testnet.vechain.energy/by/...`
97113
- **NOTE**: --gasPayerPrivateKey and --gasPayerServiceUrl are mutually exclusive.
98-
- **NOTE**: if --enableDelegation is used, --gasPayerPrivateKey OR --gasPayerServiceUrl MUST be used.
114+
- **NOTE**: if --enableDelegation is used, --gasPayerPrivateKey OR --gasPayerServiceUrl MUST be used also.
115+
116+
117+
#### Docker Run Examples
118+
119+
- default configuration pointing to testnet nodes:
120+
- `docker run -d -p 8545:8545 -e URL=https://testnet.vechain.org -t vechain/sdk-rpc-proxy:<tag>`
121+
122+
- using a configuration file:
123+
- `docker run -d -p 8545:8545 -v ./rpc-proxy-testnet-config.json:/app/packages/rpc-proxy/config.json -e CONFIGURATION_FILE=/app/packages/rpc-proxy/config.json -t vechain/sdk-rpc-proxy:<tag>`
124+
`
99125

100-
## Configuration file
126+
127+
## Configuration File
101128

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

104131
- `url`: The URL of the VeChainThor node.
105132
- `port`: The port of the proxy server.
106-
- `accounts`: The accounts that the proxy server will use to sign transactions (can be a mnemonic or an array of private
107-
keys).
133+
- `accounts`: The accounts that the proxy server will use to sign transactions (can be a mnemonic or an array of private keys).
108134
- `verbose`: Wheter to enable verbose logging.
109135
- `debug`: Whether to enable debug mode.
110136
- `enableDelegation`: Whether to enable delegation.
137+
- `gasPayer`: Specifies gasPayer private key or fee delegation service url
138+
139+
### Using Configuration file
140+
141+
For NPX useage the configuration file is passed via the `-c` or `--configurationFile` command line parameter:
142+
143+
``` bash
144+
npx rpc-proxy -c <json config file>
145+
npx rpc-proxy --configurationFile <json config file>
146+
```
147+
148+
For Docker useage the configuration file is mounted as a volume, and the env variable CONFIGURATION_FILE is set to its location:
111149

112-
### Example Configurations
150+
``` bash
151+
docker run -d -p 8545:8545 -v ./rpc-proxy-testnet-config.json:/app/packages/rpc-proxy/config.json -e CONFIGURATION_FILE=/app/packages/rpc-proxy/config.json -t vechain/sdk-rpc-proxy:<tag>
152+
```
153+
154+
### Example Configuration Files
113155

114156
Simple thor solo configuration with mnemonic:
115157

@@ -177,22 +219,7 @@ Simple testnet configuration with a gasPayer private url:
177219
}
178220
```
179221

180-
# Run as Docker Container
181-
182-
To run the RPC proxy as a Docker container, follow these steps:
183-
184-
``` bash
185-
cd ../..
186-
docker build -f docker/rpc-proxy/Dockerfile . -t vechain/sdk-rpc-proxy
187-
# To replace the default config file, update the config.json file and start a terminal from the folder in which the file is located.
188-
# DISCLAIMER: Make sure you replace the default config file before using it for production software. By default, the docker will point to testnet and use a known mnemonic.
189-
docker run -d -p 8545:8545 -v ./config.json:/app/packages/rpc-proxy/config.json -t vechain/sdk-rpc-proxy
190-
```
191-
192-
If you do not pass a config.json file, the default solo network standard configuration will be used. Make sure to
193-
provide your desired configuration file.
194-
195-
## JSON RPC Methods Support Status
222+
## Appendix - JSON RPC Methods Support Status
196223

197224
Below is the support status for JSON RPC methods in VeChain via `sdk-rpc-proxy`.
198225

@@ -262,7 +289,7 @@ Below is the support status for JSON RPC methods in VeChain via `sdk-rpc-proxy`.
262289
- **Partially Supported**: The method is implemented but may have limitations or deviations from the Ethereum standard.
263290
- **Not Supported**: The method is not implemented or cannot be supported due to protocol constraints.
264291

265-
## RPC to VeChain Mappings
292+
### RPC to VeChain Mappings
266293

267294
The following mappings are performed by the RPC proxy
268295

@@ -283,7 +310,7 @@ The method `eth_chainId` returns:
283310
* for solo or other custom networks it returns the _chainTag_ (the last byte of the genesis block id)
284311

285312

286-
## Transaction Coversions
313+
### Transaction Conversions
287314

288315
The method `eth_sendTransaction` requires the input to be a VeChain transaction object, not a Ethereum transaction object
289316
This method signs the transaction using the configured PK, before passing it on to VeChain Thor

0 commit comments

Comments
 (0)