Skip to content
Discussion options

You must be logged in to vote

You should check out this documentation to learn more about Promises. A lot of ethers returns Promises, so becoming more familiar with Promises will help you a lot, as well as for JavaScript programming in general.

You can use something akin to an async IIFE:

const ethers = require("ethers");
const url = "wss://bsc-ws-node.nariox.org:443";

const provider = new ethers.providers.WebSocketProvider(url);

// async IIFE
(async function() {
  const blockNumber = await provider.getBlockNumber();
  console.log(blockNumber);
})();

One other quick suggestion, avoid using var and instead use let and const. They will save a lot of headaches down the road. :)

Hope that helps. :)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant