0

hi I'm trying to build a contract that receives erc20 token like BUSD and transfer it to an address but it needs two confirmations. so I decided to use approve and transferFrom function but this one needs two confirms so I think ERC777 is the best way to do this. here is my code:

pragma solidity ^0.8.14;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/IERC777.sol";
import "https://github.com/fractional-company/contracts/blob/master/src/OpenZeppelin/introspection/IERC1820Registry.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/IERC777Recipient.sol";

contract Simple777Recipient is IERC777Recipient {

    IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
    bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");

    IERC777 private _token;

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

    constructor (address token) public {
        _token = IERC777(token);

        _erc1820.setInterfaceImplementer(address(this), TOKENS_RECIPIENT_INTERFACE_HASH, address(this));
    }

    function tokensReceived(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external override {
        require(msg.sender == address(_token), "Simple777Recipient: Invalid token");
        emit DoneStuff(operator, from, to, amount, userData, operatorData);
    }
}

I copied BUSD code and deployed and used its address for constructor but it's not deploying i need help for this or a new solution.

1 Answer 1

2

It's not deploying because your constructor is calling a contract (the ERC1820 registry) which doesnt exist on the chain your on. Besides that, what you're trying to do won't work, BUSD is ERC20, it's not ERC777, so it won't call the tokenReceived() function when transferring tokens to your contract.

2
  • tnx for your answer first part was helpful and i solved the problem but about second part of your answer; are you sure it's not possible? i read that all ERC20 tokens are compatible with ERC777 and we can use it's functions but there is no working example for that
    – Meysam
    Commented Jul 28, 2022 at 15:35
  • "I read that all ERC20 tokens are compatible with ERC777 and we can use it's functions". You read wrong, that's not the case at all. 777 is backwards compatible with 20, but you can't use 777 functions with ERC20 contracts
    – Foxxxey
    Commented Jul 28, 2022 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.