Verify EVM Chain ID
boxhock opened this issue · comments
Context:
We have some EAs that reads on-chain data using the JSON-RPC API. We use Ethers for this. The RPC URL is defined with env var as RPC_URL
.
Some EAs support multiple networks. In those cases, the RPC URL is defined as [network]_RPC_URL
.
Task:
For all EAs that use Ethers to call a JSON-RPC API, add verification of the chain ID. With ethers, this is done by adding the chain ID in the initialization of the JSON-RPC provider, e.g.:
new ethers.providers.JsonRpcProvider(rpcUrl)
// becomes...
new ethers.providers.JsonRpcProvider(rpcUrl, chainId)
To support this, we should add new env vars:
CHAIN_ID
for EAs that only support a single network[network]_CHAIN_ID
for EAs that support multiple networks
The default for CHAIN_ID
should be 1
, unless the EA is specifically intended for a different chain.
This would likely require a major version bump for the affected EAs, as if a node op is using the EA for a chain that isn't Ethereum mainnet, all requests would fail until re-configured with the correct chain ID.