5

I know there is web3.fromWei('myamount','ether') to convert from Wei to Ether.

But what if I have only the Gwei amount?

alper
  • 8,395
  • 11
  • 63
  • 152
Giuseppe
  • 185
  • 1
  • 2
  • 9

2 Answers2

5

You can do:

from decimal import Decimal

def covert(amount): #: Convert gwei to wei wei_amount = Decimal(amount) * (Decimal(10) ** 9) # Gigaweis are billions eth_amount = web3.fromWei(wei_amount,'ether') return wei_amount, eth_amount

alper
  • 8,395
  • 11
  • 63
  • 152
Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127
3

If you don't mind importing another library, Brownie's Wei class makes it very simple to get from gwei to wei:

>>> from brownie import Wei
>>> Wei("1 gwei")
1000000000
alper
  • 8,395
  • 11
  • 63
  • 152
iamdefinitelyahuman
  • 2,876
  • 1
  • 12
  • 32