javascriptjson-rpchedera-hashgraphhedera

When running "hedera-json-rpc-relay", how to configure a connection to Hedera Testnet?


I'm following the instructions on hedera-json-rpc-relay: Specifically docs/configuration.md, attempting to run the RPC relay connecting to Hedera Testnet:

HEDERA_NETWORK=TESTNET
OPERATOR_ID_MAIN=0.0.3996280
OPERATOR_KEY_MAIN=<redacted>
OPERATOR_ID_ETH_SENDRAWTRANSACTION=
OPERATOR_KEY_ETH_SENDRAWTRANSACTION=
CHAIN_ID=0x128
MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com/
E2E_RELAY_HOST=

Note that OPERATOR_ID_MAIN and OPERATOR_KEY_MAIN have been obtained for the portal, and have successfully been used in other transactions.

The specific instruction for HEDERA_NETWORK is:

Which network to connect to. Automatically populates the main node & mirror node endpoints. Can be MAINNET, PREVIEWNET, TESTNET or a map of network IPs -> node accountIds e.g. {"127.0.0.1:50211":"0.0.3"}

However, when I run npm run start, I get the following error Error: unknown network: TESTNET ... even though this explicitly is an allowed value according to the docs.

(Full output copied below the <hr/>).

What is the correct config to start the RPC relay and connect it to Hedera Testnet?


> start
> npx lerna exec --scope @hashgraph/json-rpc-server -- npm run start

lerna notice cli v6.4.1
lerna info versioning independent
lerna notice filter including "@hashgraph/json-rpc-server"
lerna info filter [ '@hashgraph/json-rpc-server' ]
lerna info Executing command in 1 package: "npm run start"

> @hashgraph/json-rpc-server@0.23.0-SNAPSHOT start
> node dist/index.js

[2023-04-21 03:25:43.036 +0000] INFO (rpc-server/97941 on admins-MBP): Configurations successfully loaded
/Users/user/code/hedera/hedera-json-rpc-relay/node_modules/@hashgraph/sdk/lib/client/NodeClient.cjs:279
        throw new Error(
        ^

Error: unknown network: TESTNET
    at NodeClient._setNetworkFromName (/Users/user/code/hedera/hedera-json-rpc-relay/node_modules/@hashgraph/sdk/lib/client/NodeClient.cjs:279:15)
    at new NodeClient (/Users/user/code/hedera/hedera-json-rpc-relay/node_modules/@hashgraph/sdk/lib/client/NodeClient.cjs:94:14)
    at NodeClient.forName (/Users/user/code/hedera/hedera-json-rpc-relay/node_modules/@hashgraph/sdk/lib/client/NodeClient.cjs:164:12)
    at RelayImpl.initClient (/Users/user/code/hedera/hedera-json-rpc-relay/packages/relay/dist/lib/relay.js:69:35)
    at new RelayImpl (/Users/user/code/hedera/hedera-json-rpc-relay/packages/relay/dist/lib/relay.js:42:32)
    at Object.<anonymous> (/Users/user/code/hedera/hedera-json-rpc-relay/packages/server/dist/server.js:57:15)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)

Node.js v18.15.0
npm ERR! Lifecycle script `start` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: @hashgraph/json-rpc-server@0.23.0-SNAPSHOT 
npm ERR!   at location: /Users/user/code/hedera/hedera-json-rpc-relay/packages/server 
lerna ERR! npm run start exited 1 in '@hashgraph/json-rpc-server'
lerna ERR! npm run start exited 1 in '@hashgraph/json-rpc-server'

Solution

  • This is the config that was necessary:

    HEDERA_NETWORK=testnet
    OPERATOR_ID_MAIN=0.0.3996280
    OPERATOR_KEY_MAIN=<...redacted...>
    CHAIN_ID=0x128
    MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com/
    

    Submitted a patch to add the sample files for the above, plus equivalents for Hedera Mainnet and Hedera Previewnet as well.

    Also, the error that occurred was because of this line:

    HEDERA_NETWORK=TESTNET
    

    It essentially failed because it only accepted all lowercase. This has also been fixed in the same patch, so now the original config from the question will start working as well.