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
The amount to send in represented in Wei
So for representing
5 ether
you can use5*(10^18)
and for representing50 Gwei
you can use50*(10^9)
.There are web3 methods to directly convert these units in web3 docs.