Last active
March 4, 2022 19:06
-
-
Save italosantana/0538b46e55c772537c7f1ea01abfa834 to your computer and use it in GitHub Desktop.
Querying the Blockchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Look up the current block number | |
await provider.getBlockNumber() | |
// 14135476 | |
// Get the balance of an account (by address or ENS name, if supported by network) | |
balance = await provider.getBalance("ethers.eth") | |
// { BigNumber: "82826475815887608" } | |
// Often you need to format the output to something more user-friendly, | |
// such as in ether (instead of wei) | |
ethers.utils.formatEther(balance) | |
// '0.082826475815887608' | |
// If a user enters a string in an input field, you may need | |
// to convert it from ether (as a string) to wei (as a BigNumber) | |
ethers.utils.parseEther("1.0") | |
// { BigNumber: "1000000000000000000" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment