1 min read - Posted 18 Dec 19

Converting Between Ether Units / Denominations in Web3j

The smallest denomination of ether is called wei, and you will often find yourself needing to convert to and from wei when interacting with Ethereum smart contracts. Luckily, web3j provides a Convert library class that simplifies this task.

Here are some examples:

From Wei to Ether

BigInteger valueInWei = ...;

BigInteger convertedToEther = Convert.fromWei(valueInWei, Unit.ETHER);

From Ether to Wei

BigInteger valueInEther = ...;

BigInteger convertedToWei = Convert.toWei(valueInEther, Unit.ETHER);

From Wei to Gwei

BigInteger valueInWei = ...;

BigInteger convertedToGwei = Convert.fromWei(valueInWei, Unit.GWEI);

From Gwei to Wei

BigInteger valueInGwei = ...;

BigInteger convertedToWei = Convert.toWei(valueInGwei, Unit.GWEI);
Created with Sketch.Content is"CC-BY-SA 4.0" licensed
Article On-chain
Article Author

Craig Williams

Software Developer @ Kauri / ConsenSys




Related Articles
Retrieving an Ethereum Account Balance in Web3j

Balance at Current Block To obtain the balance of an account in java with web3j at the current block, the following code snippet can be used://Connect to node.

Manage an Ethereum account with Java and Web3j

Other articles in this series: Connecting to an Ethereum client with Java, Eclipse and Web3j Generate a Java Wrapper from your Smart Contract Interacting with a