1

When a market transaction is happening, on the ERC20 token interface approve and transferFrom return true, so, after these two returns I know I can do some stuff like execute a NFT transfer. But on ERC777 send method dont return nothing. How could I realize if anyone paid in order to forward in my operation?

Ex.:

//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);
Gi Ro
  • 11
  • 1
  • Here is an example: https://github.com/Dawn-Protocol/dawn-erc20-erc777/blob/master/contracts/Staking.sol#L243 – Mikko Ohtamaa Nov 14 '21 at 20:09
  • Let me know if I understand. In a smartcontract to sell NFT, for example, I start a selling on a sellItem method, call token.send() and then I perform the NFT transfer inside tokensReceived method? – Gi Ro Nov 14 '21 at 20:56
  • Yes - sounds about right. – Mikko Ohtamaa Nov 15 '21 at 09:56

1 Answers1

0

without more context and just these lines of code, it's difficult to answer precisely.

Do you go through a DEFI smart contract that handles the transaction? or is it a full exchange contract?

So here are some general clues, but I will be able to answer more accurately if you answer the previous.

When you look at the ERC777 documentation, you can see that sentence:

The token contract MUST emit a Sent event with the correct values as defined in the Sent Event.

the idea is that you (or the other contract) must create an event to see if the transfer is done or not.

Maybe this example can help you.

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);
    }
}
Gwenael
  • 66
  • 3