0

I'm trying to call eth_getBlockByNumber using Web3WsProvider of ethers.js with the following code:

const Web3WsProvider = require('web3-providers-ws');
.
.
.

const provider = new Web3WsProvider("wss://api.avax-test.network/ext/bc/C/ws", options);
this.client = new ethers.providers.Web3Provider(provider);



const res = await (this.client as ethers.providers.Web3Provider).send(
      "eth_getBlockByNumber", ["0x0", false]
);

but I get an error

Error: the method eth_getBlockByNumber does not exist/is not available

I am able to make this call through postman and get back a result. Why am I not able to do the same with ethers.js

1 Answer 1

0

I guess you can use this example:

const ethers = require("ethers");
(async () => {
  const provider = new ethers.providers.JsonRpcProvider("http://sample-endpoint-name.network.quiknode.pro/token-goes-here/");
  const blockData = await provider.getBlock("0xc5043f");
  console.log(blockData);
})();

Taken from here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.