1.0.0 • Published 4 months ago

@vechain/sdk-rpc-proxy v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@vechain/sdk-rpc-proxy

Welcome to the RPC Proxy of the VeChain SDK!

Introduction

The RPC Proxy is designed to bridge the gap between Thor's RESTful API and Ethereum's JSON-RPC, enabling seamless interaction with the VeChainThor blockchain through RPC calls. It is particularly useful for integrating with tools such as the Remix IDE.

Installation

To install the RPC proxy, use the following command:

yarn add @vechain/sdk-rpc-proxy

Usage

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

npx 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:

npx rpc-proxy -c <json config file>

Or:

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

CLI Options

With rpc-proxy, you can use the following CLI options. 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.- npx rpc-proxy -p 8545 -v ...
  • a custom configuration file and override some values with the cli options

    • -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.- 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.- npx rpc-proxy -p 8545 OR rpc-proxy --port 8545
  • -u, --url <url>: The URL of the VeChainThor node.

    • -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.- 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.- 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.- 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.
  • --gasPayerPrivateKey <gasPayerPrivateKey>: The private key of the gasPayer.
  • -s, --gasPayerServiceUrl <gasPayerServiceUrl>: The URL of the gasPayer.
    • -e.g.- npx rpc-proxy -e --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 OR npx rpc-proxy --enableDelegation --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158
    • -e.g.- npx rpc-proxy -e -s https://sponsor-testnet.vechain.energy/by/... OR npx rpc-proxy --enableDelegation --gasPayerServiceUrl https://sponsor-testnet.vechain.energy/by/...
    • NOTE: --gasPayerPrivateKey and --gasPayerServiceUrl are mutually exclusive.
    • NOTE: if --enableDelegation is used, --gasPayerPrivateKey OR --gasPayerServiceUrl MUST be used.

Configuration file

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

  • url: The URL of the VeChainThor node.
  • port: The port of the proxy server.
  • accounts: The accounts that the proxy server will use to sign transactions (can be a mnemonic or an array of private keys).
  • verbose: Wheter to enable verbose logging.
  • debug: Whether to enable debug mode.
  • enableDelegation: Whether to enable delegation.

Example Configurations

Simple thor solo configuration with mnemonic:

{
    "url": "http://127.0.0.1:8669",
    "port": 8545,
    "accounts": {
        "mnemonic": "denial kitchen pet squirrel other broom bar gas better priority spoil cross",
        "count": 10
    },
    "verbose": true,
    "enableDelegation": false
}

Simple thor solo configuration with accounts as a list of private keys:

{
    "url": "http://127.0.0.1:8669",
    "port": 8545,
    "accounts": [
        "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158",
        "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
    ],
    "verbose": true,
    "enableDelegation": false
}

Simple testnet configuration with a gasPayer private key:

{
  "url": "https://testnet.vechain.org",
  "port": 8545,
  "accounts": {
    "mnemonic": "expire pair material agent north ostrich fortune level cousin snow mixture nurse",
    "count": 10,
    "initialIndex": 0
  },
  "gasPayer": {
    "gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
  },
  "enableDelegation": true
}

Simple testnet configuration with a gasPayer private url:

{
  "url": "https://testnet.vechain.org",
  "port": 8545,
  "accounts": {
    "mnemonic": "expire pair material agent north ostrich fortune level cousin snow mixture nurse",
    "count": 10,
    "initialIndex": 0
  },
  "gasPayer": {
    "gasPayerServiceUrl": "https://sponsor-testnet.vechain.energy/by/..."
  },
  "enableDelegation": true
}

Run as Docker Container

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

cd ../..
docker build -f docker/rpc-proxy/Dockerfile . -t vechain/sdk-rpc-proxy
# To replace the default config file, update the config.json file and start a terminal from the folder in which the file is located. 
# 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. 
docker run -d -p 8545:8545 -v ./config.json:/app/packages/rpc-proxy/config.json -t vechain/sdk-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.

JSON RPC Methods Support Status

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

JSON RPC MethodSupport Status
debug_traceBlockByHashFully Supported
debug_traceBlockByNumberFully Supported
debug_traceCallFully Supported
debug_traceTransactionFully Supported
eth_accountsFully Supported
eth_blockNumberFully Supported
eth_callPartially Supported
eth_chainIdFully Supported
eth_coinbaseFully Supported
eth_createAccessListFully Supported
eth_estimateGasPartially Supported
eth_gasPriceFully Supported
eth_getBalanceFully Supported
eth_getBlockByHashPartially Supported
eth_getBlockByNumberPartially Supported
eth_getBlockReceiptsFully Supported
eth_getBlockTransactionCountByHashFully Supported
eth_getBlockTransactionCountByNumberFully Supported
eth_getCodeFully Supported
eth_getLogsPartially Supported
eth_getStorageAtFully Supported
eth_getTransactionByBlockHashAndIndexFully Supported
eth_getTransactionByBlockNumberAndIndexFully Supported
eth_getTransactionByHashFully Supported
eth_getTransactionCountPartially Supported
eth_getTransactionReceiptFully Supported
eth_getUncleByBlockHashAndIndexPartially Supported
eth_getUncleByBlockNumberAndIndexPartially Supported
eth_getUncleCountByBlockHashPartially Supported
eth_getUncleCountByBlockNumberPartially Supported
eth_requestAccountsFully Supported
eth_sendRawTransactionFully Supported
eth_sendTransactionFully Supported
eth_signTransactionFully Supported
eth_signTypedDataV4Fully Supported
eth_subscribeFully Supported
eth_syncingPartially Supported
eth_unsubscribeFully Supported
evm_mineFully Supported
net_listeningFully Supported
net_peerCountFully Supported
net_versionFully Supported
txpool_contentPartially Supported
txpool_contentFromPartially Supported
txpool_inspectPartially Supported
txpool_statusPartially Supported
web3_clientVersionFully Supported
web3_sha3Fully Supported
eth_getUncleByBlockHashNot Supported
eth_getUncleByBlockNumberNot Supported
eth_newFilterNot Supported
eth_newBlockFilterNot Supported
eth_newPendingTransactionFilterNot Supported
eth_uninstallFilterNot Supported
eth_getFilterChangesNot Supported
eth_getFilterLogsNot Supported
eth_getProofNot Supported
txpool_inspectFromNot Supported

Notes

  • Fully Supported: The method is implemented and works as expected.
  • Partially Supported: The method is implemented but may have limitations or deviations from the Ethereum standard.
  • Not Supported: The method is not implemented or cannot be supported due to protocol constraints.

RPC to VeChain Mappings

The following mappings are performed by the RPC proxy

RPC ParameterVeChain Parameter
block hashblock id
latest blockbest block
safe blockjustified block
finalized blockfinalized block
pending blockbest block
earliest blockblock number 0

The method eth_chainId returns:

  • 0x186a9 for mainnet
  • 0x186aa for testnet
  • for solo or other custom networks it returns the chainTag (the last byte of the genesis block id)

Transaction Coversions

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

For method eth_sendRawTransaction the signed encoded raw transaction parameter must be a vechain transaction object
This method cannot convert a signed Ethereum transaction to a signed VeChain transaction

1.0.0

4 months ago

2.0.0-beta.1

5 months ago

1.0.0-rc.6

5 months ago

1.0.0-rc.5

6 months ago

1.0.0-rc.4

7 months ago

1.0.0-rc.3

7 months ago

1.0.0-rc.1

8 months ago

1.0.0-rc.2

7 months ago

1.0.0-beta.32

9 months ago

1.0.0-beta.31

9 months ago

1.0.0-beta.30

10 months ago

1.0.0-beta.28

11 months ago

1.0.0-beta.29

11 months ago

1.0.0-beta.27

11 months ago

1.0.0-beta.26

11 months ago

1.0.0-beta.25

11 months ago

1.0.0-beta.23

11 months ago

1.0.0-beta.24

11 months ago

1.0.0-beta.22

11 months ago

1.0.0-beta.20

12 months ago

1.0.0-beta.21

12 months ago

1.0.0-beta.19

12 months ago

1.0.0-beta.17

1 year ago

1.0.0-beta.18

12 months ago

1.0.0-beta.16

1 year ago

1.0.0-beta.15

1 year ago

1.0.0-beta.13

1 year ago

1.0.0-beta.14

1 year ago

1.0.0-beta.11

1 year ago

1.0.0-beta.12

1 year ago

1.0.0-beta.10

1 year ago

1.0.0-beta.6

1 year ago

1.0.0-beta.7

1 year ago

1.0.0-beta.8

1 year ago

1.0.0-beta.9

1 year ago

1.0.0-beta.5

1 year ago

1.0.0-beta.4

1 year ago

1.0.0-beta.3

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-beta.0

1 year ago