simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
441 stars 270 forks source link

I want to turn 0.01 ETH #199

Closed TransFormes closed 2 years ago

TransFormes commented 2 years ago

I can change to 1ETH, but I want to change to 0.01, but the error is reported, how should I change

TransFormes commented 2 years ago

final transfer = contract.function('transfer'); var res1 = await client.sendTransaction( credentials, Transaction.callContract( contract: contract, function: transfer, from: EthereumAddress(credentials.address.addressBytes), parameters: [ EthereumAddress(credentials.address.addressBytes), BigInt.from(1) ], value: EtherAmount.fromUnitAndValue(EtherUnit.ether, '0.01')), chainId: 4);

TransFormes commented 2 years ago

I can send 0.01 ETH using Web3

var result = await client.transfer( privateKey: 'privateKey', toAddress: 'toAddress', amount: 0.1);

simolus3 commented 2 years ago

Using doubles as a monetary amount isn't a great idea. You can use EtherAmount.fromUnitAndValue(EtherUnit.finney, 10) though.