【问题标题】:Failed Transaction on Ethereum以太坊交易失败
【发布时间】:2021-05-16 13:26:17
【问题描述】:

我玩过一段时间的自制程序。我只是试图在我之前购买的 uniswap 上出售一些随机代币。我的交易不知何故没有通过,我不知道为什么。

https://etherscan.io/tx/0xcb4ef6baab722e00e6dad75d12398fc88cc5177445758064a14c8433612a860f

有人知道为什么它没有通过吗,我对 Solidity/ethereum 还不够熟悉。

非常感谢。

【问题讨论】:

标签: ethereum solidity go-ethereum


【解决方案1】:

我们可以通过搜索合约TRANSFER_FROM_FAILED中的消息来检查交易未能满足哪些要求。

该函数调用 transferFrom 函数。 transferFrom 功能需要令牌的所有者批准支出者代表他/她进行支出。

您似乎尚未批准该支出者代表您进行支出。

您可以在docs查看有关 transferFrom 的更多信息

// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');

swapExactTokensForETH 使用safeTransferFrom 函数

...
TransferHelper.safeTransferFrom( 
   path[0], 
   msg.sender, 
   UniswapV2Library.pairFor(factory, path[0], path[1]),
    amounts[0]
);
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-02
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2017-01-27
    • 2021-11-25
    相关资源
    最近更新 更多