【问题标题】:How to use ERC777 as a pay method如何使用 ERC777 作为支付方式
【发布时间】:2021-12-26 04:31:34
【问题描述】:

当发生市场交易时,在 ERC20 代币接口上,approve 和 transferFrom 返回 true,因此,在这两个返回之后,我知道我可以做一些事情,比如执行 NFT 转账。 但是在 ERC777 发送方法上不返回任何内容。如果有人为转发我的操作而付费,我怎么知道?

例如:

//ERC20
if (token.approve(address(this), amount)) {
      if (token.transferFrom(msg.sender, idToMarketItem[itemId].seller, amount)) {
        IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);
      }
    }
//ERC777

 token.send(idToMarketItem[itemId].seller, amount, "");
 //????
 IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);

【问题讨论】:

  • 如果我明白了,请告诉我。例如,在出售 NFT 的智能合约中,我开始出售 sellItem 方法,调用 token.send(),然后在 tokensReceived 方法中执行 NFT 转账?
  • 是的 - 听起来很对。

标签: blockchain ethereum solidity smartcontracts openzeppelin


【解决方案1】:

没有更多的上下文,只有这几行代码,很难准确回答。

您是否通过处理交易的 DEFI 智能合约? 还是完整的交换合约?

所以这里是一些一般性的线索,但如果你回答上一个,我将能够更准确地回答。

当你查看ERC777文档时,你可以看到那句话:

代币合约必须发出一个 Sent 事件,其值在 Sent Event 中定义正确。

这个想法是你(或其他合约)必须创建一个事件来查看转移是否完成。

也许这个例子可以帮助你。

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC777/IERC777.sol";
import "@openzeppelin/contracts/introspection/IERC1820Registry.sol";
import "@openzeppelin/contracts/introspection/ERC1820Implementer.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Sender.sol";

contract Simple777Sender is IERC777Sender, ERC1820Implementer {

    bytes32 constant public TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");

    event DoneStuff(address operator, address from, address to, uint256 amount, bytes userData, bytes operatorData);

    function senderFor(address account) public {
        _registerInterfaceForAddress(TOKENS_SENDER_INTERFACE_HASH, account);
    }

    function tokensToSend(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external {

        // do stuff
        emit DoneStuff(operator, from, to, amount, userData, operatorData);
    }
}

【讨论】:

    猜你喜欢
    • 2017-10-26
    • 2017-08-05
    • 2014-03-16
    • 2011-02-22
    • 2016-07-06
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多