Skip to content

Latest commit

 

History

History
 
 

connect-ethersjs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Connect to Hedera Testnet via EthersJs

This code snippets demonstrates how to connect to Hedera Testnet using EthersJs (v5).

Code

Copy the .env.example file to .env, then edit it to add the URL for a JSON-RPC endpoint for Hedera Testnet.

To obtain this URL, see the JSON-RPC connections documentation.

In the connect.js file in this directory, an instance of ethers.providers.JsonRpcProvider is initialised using the JSON-RPC endpoint. The CORS HTTP header (Access-Control-Allow-Origin) is set to be maximally permissive. This is needed for in-browser usage, but not needed for usage in NodeJs.

Subsequently a couple of RPCs are invoked to obtain the block number, and the HBAR balance of a specified account. These are simply to verify that the connection works properly.

References