rpchedera-hashgraphhedera

How can I connect to Hedera Testnet over RPC? ​


I am unable to connect to a Hedera Testnet RPC endpoints over HTTP, reliably, I get the following "Unknown error" intermittently: ​

[Request ID: fe7b9928-a23f-0d72-61a1-b7cd23658c01] Unknown error invoking RPC

​ I'm connecting using the following RPC endpoint: ​

https://testnet.hashio.io/api

​ Are there alternative (more reliable) ways to connect to the Hedera Testnet? ​


Solution

  • There are 3 options to connect to Hedera Testnet:

    The above are listed in increasing order of difficulty levels, and increasing order of reliability levels. Unfortunately for increased reliability you need to do a bit more work.

    Currently, you're using Hashio, and I speculate that you may be getting rate limited; or this service might be under higher-than-usual load levels causing it to drop some of its incoming requests. Therefore I suggest that you switch to using Arkhia, and see if that works out for you (chances are it will). And if you really want to minimise reliance on centralised services, or need to debug individual RPC requests, you can consider running your own instance of the RPC relay locally.


    RPC endpoint options

    Hashio

    This is a "public" RPC endpoint, hosted by Swirlds Labs, the same organisation that develops Hedera. As such, it is free to use, and does not require any sign up, and also has the most restrictive rate limits on requests made to it. This makes it easy to use, but not too reliable.

    To connect to the Hedera Testnet via Hashio, simply use this URL when initialising the wallet/ web3 provider instance:

    https://testnet.hashio.io/api
    

    That's all that's needed - no further settings/ config needed

    Arkhia

    This is run by a 3rd party organisation, and has some paid components, with a free tier. As such, it is free to use only up until a point, and requires a sign up thereafter. It has less restrictive rate limits on requests made to it. This makes it about average in terms of ease of use, and also more reliable than using the public RPC endpoint.

    To connect to Hedera Testnet via Arkhia, use this URL when initialising the wallet/ web3 provider instance:

    https://pool.arkhia.io/hedera/testnet/json-rpc/v1/YOUR_API_KEY
    

    In order to get YOUR_API_KEY, you will need to do the following pre-requisite steps:

    hedera-json-rpc-relay on localhost

    This is run by you on your own computer. (Decentralisation for the win!) As such it is free to use without limits (except that of your own hardware). It does not require sign up, but there are several additional steps required to set it up, and requires developer skills/ command line skills to get working.

    To connect to Hedera Testnet via your own instance of hedera-json-rpc-relay, use this URL when initialising the wallet/ web3 provider instance:

    http://localhost:7546
    

    Note that 7546 is the default port number for this project, and you can change this in its config if you wish.

    In order to get this service running, you will need to do the following pre-requisite steps:

    git clone git@github.com:hashgraph/hedera-json-rpc-relay.git
    
    HEDERA_NETWORK=testnet
    OPERATOR_ID_MAIN=YOUR_OPERATOR_ID
    OPERATOR_KEY_MAIN=YOUR_OPERATOR_KEY
    CHAIN_ID=0x128
    MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com/
    

    Full reference for configuring hedera-json-rpc-relaydocs/configuration.md.