How to convert ether from wei (and vice versa) with Web3 1.0.0
1 min readMay 14, 2018
- Ethereum’s currency which is “Ether” has several units.
- The minimum unit of Ether is called “wei”.
- 1 ether = 1000000000000000000 wei.
Install Web3
- Web3 is a JavaScript library which can interact with Ethereum.
$ npm install web3
Example code
- How to convert ether from wei (and vice versa) with Web3 1.0.0
var Web3 = require('web3');
console.log(Web3.version);
// => 1.0.0-beta.34
const weiValue = Web3.utils.toWei('1', 'ether');
console.log(weiValue);
// => 1000000000000000000
const etherValue = Web3.utils.fromWei('1000000000000000000', 'ether');
console.log(etherValue);
// => 1