2.8.2 • Published 10 days ago

@acala-network/eth-rpc-adapter v2.8.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 days ago

@acala-network/eth-rpc-adapter

A node service that provides JSON-RPC for Acala EVM+, in order for existing Ethereum dApp and tools to interact with EVM+ with minumum changes.

Run

First run a Mandala node locally

docker run -it --rm -p 9944:9944 -p 9933:9933 ghcr.io/acalanetwork/mandala-node:sha-104e277 --dev --ws-external --rpc-port=9933 --rpc-external --rpc-cors=all --rpc-methods=unsafe -levm=debug --pruning=archive --instant-sealing

Then there are 3 ways to run an RPC adapter:

  • from docker
  • from npm package
  • from local build

from docker

docker run -it --rm -e LOCAL_MODE=1 -p 8545:8545 acala/eth-rpc-adapter:v2.5.3 yarn start

latest image can be found here

from npm package

npx @acala-network/eth-rpc-adapter \
  --endpoint ws://localhost:9944 \
  --local-mode

from local build

  • build it locally
rush update
rush build -t @acala-network/eth-rpc-adapter 
  • run the dev server:
yarn start --local-mode [--other-options]

Options

NOTE: Please don't mix using ENVs and cli options. Cli options are preferred, and will overwrite ENVs.

More details can also be found by yarn start --help or npx @acala-network/eth-rpc-adapter --help.

ENVcli options equivalentdefaultexplanation
ENDPOINT_URL-e, --endpointws://localhost:9944Node websocket endpoint(s): can provide one or more endpoints, seperated by comma url
SUBQL_URL--subqlundefinedSubquery url: optional if testing contracts locally that doesn\'t query logs or historical Tx, otherwise required
PORT-p, --port8545port to listen for http and ws requests
MAX_CACHE_SIZE--max-cache-size200max number of blocks that lives in the cache more info
MAX_BATCH_SIZE--max-batch-size50max batch size for RPC request
STORAGE_CACHE_SIZE--max-storage-size5000max storage cache size
SAFE_MODE-s, --safe-mode0if enabled, TX and logs can only be found after they are finalized
LOCAL_MODE-l, --local-mode0enable this mode when testing with locally running instant-sealing mandala
RICH_MODE-r, --rich-mode0if enabled, default gas params is big enough for most contract deployment and calls, so contract tests from traditional evm world can run unchanged. Note this mode is helpful for testing contracts, but is different than production envionment. more info
HTTP_ONLY--http-only0only allow http requests, disable ws connections
VERBOSE-v, --verbose1print some extra info

Usage

Now that the adaptor service is running and listening to the --port, we can send Eth JsonRpc requests to this port (both GET and POST are supported).

For example

### request
curl --location --request GET 'http://localhost:8545' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_chainId",
    "params": [],
    "id": 1
}'

### response
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "0x253"
}

Available RPCs

ETH compatible RPCs

These are ETH compatible RPCs, the interface and functionalities match https://eth.wiki/json-rpc/API

  • web3_clientVersion
  • net_version
  • eth_blockNumber
  • eth_chainId
  • eth_getTransactionCount
  • eth_getCode
  • eth_call
  • eth_getBalance
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_gasPrice
  • eth_accounts
  • eth_getStorageAt
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_sendRawTransaction
  • eth_estimateGas
  • eth_getTransactionByHash
  • eth_getTransactionReceipt
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getUncleCountByBlockHash
  • eth_getUncleCountByBlockNumber
  • eth_getUncleByBlockHashAndIndex
  • eth_getUncleByBlockNumberAndIndex
  • eth_getLogs
  • eth_subscribe
  • eth_unsubscribe
  • eth_newFilter
  • eth_newBlockFilter
  • eth_getFilterLogs (doesn't support unfinalized logs yet)
  • eth_getFilterChanges (doesn't support unfinalized logs yet)
  • eth_uninstallFilter

Custom RPCs

These are EVM+ custom RPCs that only exist on Acala/Karura

  • eth_getEthGas: calculate eth transaction gas params from substrate gas params. More details please refer here]
  • eth_getEthResources: calculate eth transaction gas params from transaction details, params: TransactionRequest
  • net_indexer: get subql indexer metadata
  • net_cacheInfo: get the cache info
  • net_isSafeMode: check if this RPC is running in safe mode
  • net_health: check the health of the RPC endpoint
  • net_runtimeVersion: check the current runtime version of the underlying polkadot.js api
  • eth_isBlockFinalized: check if a block is finalized, params: BlockTag
  • eth_isTransactionFinalized: check if a transaction is finalized, note that it also returns false for non-exist tx, params: string

Integrate Metamask Locally

As Eth RPCs are now available locally, we can connect metamask to it

  • start the RPC server locally: yarn start --local
  • add a custom network on Metamask:
  • import dev address to metamask:
    • by nmemonic: fox sight canyon orphan hotel grow hedgehog build bless august weather swarm
    • or by private key: 0xa872f6cbd25a0e04a08b1e21098017a9e6194d101d75e13111f71410c59cd57f

tips

  • before sending any transaction, please don't change the default gasPrice or GasLimit, otherwise transaction will fail. more info
  • everytime we restart the local network, we need to reset metamask for local network, so the nonce and cache will be cleared: settings => advanced => reset account

Modes

safe mode (deprecated)

In this mode, Txs and logs can only be found after they are finalized. Now deprecated in favor for the finalized and safe block tags.

local mode

For local testing, we usually turn this mode on, together with a local --instant-sealing mandala node. It has some optimization to run faster with local node, and some minor bug prevention.

rich mode

We usually need to specify gas params for some transactions, this is sometimes time-consuming for contract testing, especially with hardhat where we can't override gas params in config.

In rich mode, default gas params are much bigger than normal, so we don't need to worry about overriding gas params when running tests. As a result, all truffle/hardhat tests can be run unchanged.

We still recommend reading through the gas params and understand how gas works in EVM+, since in prod we might still need to override gas params.

For Production

For production deployment we can simply use acala/eth-rpc-adapter directly. Remember NOT to turn on local mode or rich mode

Run Tests Locally

  • start local mandala node + subql stacks
cd ../evm-subql
yarn && yarn build
docker compose up
  • start rpc adapter
rush update && rush build -t .
yarn start -l --subql http://localhost:3001
  • feed deterministic txs (after this step there should be 22 blocks)
cd ../examples/waffle/dex/ && yarn test
cd ../e2e/ && yarn test
  • run tests
SKIP_PUBLIC=true yarn mocha **/*.test.ts
2.8.2

10 days ago

2.8.1

18 days ago

2.8.0

1 month ago

2.7.25

1 month ago

2.7.24

1 month ago

2.7.23

2 months ago

2.7.22

2 months ago

2.7.21

3 months ago

2.7.20

3 months ago

2.7.19

4 months ago

2.7.18

4 months ago

2.7.17

5 months ago

2.7.16

5 months ago

2.7.15

5 months ago

2.7.14

5 months ago

2.7.13

6 months ago

2.7.12

6 months ago

2.7.4

11 months ago

2.7.6

9 months ago

2.7.5

10 months ago

2.7.8

8 months ago

2.7.7

9 months ago

2.7.9

7 months ago

2.7.5-0

10 months ago

2.7.5-1

10 months ago

2.7.11

7 months ago

2.7.10

7 months ago

2.7.3

12 months ago

2.7.2

12 months ago

2.7.0-0

12 months ago

2.6.10-0

12 months ago

2.6.10

12 months ago

2.7.0

12 months ago

2.7.1

12 months ago

2.6.7

1 year ago

2.6.6

1 year ago

2.6.9

12 months ago

2.6.8

1 year ago

2.6.3

1 year ago

2.6.5

1 year ago

2.6.4

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.6.2

1 year ago

2.5.21

1 year ago

2.5.22

1 year ago

2.5.20

1 year ago

2.5.18

1 year ago

2.5.19

1 year ago

2.5.14

1 year ago

2.5.15

1 year ago

2.5.17

1 year ago

2.5.9

1 year ago

2.5.10

1 year ago

2.5.11

1 year ago

2.5.12

1 year ago

2.5.13

1 year ago

2.5.4

1 year ago

2.5.3

2 years ago

2.5.6

1 year ago

2.5.5

1 year ago

2.5.8

1 year ago

2.5.7

1 year ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.4.21

2 years ago

2.4.18

2 years ago

2.4.17

2 years ago

2.4.19

2 years ago

2.4.14

2 years ago

2.4.13

2 years ago

2.4.16

2 years ago

2.4.15

2 years ago

2.4.20

2 years ago

2.4.12

2 years ago

2.4.7

2 years ago

2.4.9

2 years ago

2.4.8

2 years ago

2.4.10

2 years ago

2.4.11

2 years ago

2.4.6

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.1

2 years ago