Created
March 31, 2022 15:13
-
-
Save duanescarlett/6d2e7285efe628724f15ae32df530f40 to your computer and use it in GitHub Desktop.
This converts from decimal to wei then from wei to decimal
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
const Web3 = require('web3') | |
require('dotenv').config() | |
const main = async () => { | |
// Connect to a EVM blockchain | |
const web3 = new Web3(Web3.givenProvider || process.env.INFURA_URL) | |
// Convert from a decimal number to a wei number | |
let amt = web3.utils.toWei('0.1', 'ether') | |
console.log('Convert from a decimal number to a wei number', amt) | |
// Convert from a wei number to a decimal number | |
amt = web3.utils.fromWei(amt, 'ether') | |
console.log('Convert from a wei number to a decimal number', amt) | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((err) => { | |
console.error(err) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment