我试图估计ERC20令牌交易的天然气费--在这种情况下,把DAI从一个地址转移到另一个地址(在孟买)。
估计煤气费的代码:
final contract = DeployedContract(ContractAbi.fromJson(abi, token.id), // 'dai'
EthereumAddress.fromHex(token.contractAddress)); // 0xcB1e72786A6eb3b44C2a2429e317c8a2462CFeb1
final transferFunction = contract.function('transferFrom');
final transaction = Transaction.callContract(
contract: contract,
function: transferFunction,
parameters: [
EthereumAddress.fromHex(address), // 0x2970C7181450B6c13071131f0005ccA18436c12B
EthereumAddress.fromHex(recipientAddress), // 0xc7c6BAEA62Ff6BBAca799156CC4e9f50BC9e8060
10000000000000, // 0.001 Dai
],
);
final fee = await _client.estimateGas(
to: transaction.to,
value: transaction.value,
data: transaction.data,
);然而,我得到了RPCError: got code 3 with msg "execution reverted: Dai/insufficient-allowance"。发件人地址持有足够的令牌(大约。0.0038戴)。我首先尝试用相同的数量调用approve,但是我得到了一个不同的例外,RPCError: got code -32000 with msg "already known".,气体估计仍然失败。
关于如何用web3dart进行正确估计的一些想法
发布于 2022-07-06 11:01:09
尝试将发件人添加到estimateGas函数中,
final fee = await _client.estimateGas(
sender: EthereumAddress.fromHex(fromAddress),
to: transaction.to,
value: transaction.value,
data: transaction.data,
);https://stackoverflow.com/questions/72082270
复制相似问题