How to connect to custom Provider using ethers?

Viewed 469

How do you create a new Provider using a custom node url using the ethers package?

Looking to do something like this:

 const provider = new ethers.providers.Web3Provider('http://my-node.com')
1 Answers

In the documentation here it says to use JsonRpcProvider instead of Web3Provider.

// When using the JSON-RPC API, the network will be automatically detected


// Default: http://localhost:8545
let httpProvider = new ethers.providers.JsonRpcProvider();


// To connect to a custom URL:
let url = "http://something-else.com:8546";
let customHttpProvider = new ethers.providers.JsonRpcProvider(url);


// Connect over named pipes using IPC:
let path = "/var/run/parity.ipc";
let ipcProvider = new ethers.providers.IpcProvider(path);
Related