[Ethereum] what unit is used for the gas/gas limit in the ethereum/types lib

go-ethereumraw-transaction

I'm trying to create a raw transaction using NewTransaction send 1ETH to one transaction, set 21000 gasLimit(I understand this is fixed for any simple transaction) and set the gas price to 51 Gwei.

The issue I have is that there is no documentation about the unit used for Amount, gasLimit and gasPrice. Is it safe to use big.NewInt(1) (for 1ETH), uint64(21000) for gasLimit and big.NewInt(51) for gasPrice ?

NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit 
uint64, gasPrice *big.Int, data []byte) *Transaction

Best Answer

Everything is represented in Wei. Wei is the smallest unit of ethereum. Gas limit (in your case 21000) is just 21000. Gas price is represented in Gwei

1 Gwei = 10^9 Wei = 1,000,000,000 Wei

The amount to send in represented in Wei

1 Ether = 10^18 Wei = 1,000,000,000,000,000,000 Wei

So for representing 5 ether you can use 5*(10^18) and for representing 50 Gwei you can use 50*(10^9) .

There are web3 methods to directly convert these units in web3 docs.

Related Topic