Simple ERC777 token example

This is great, thanks for sharing it!

3 Likes

Documentation for the OpenZeppelin ERC777 implementation:

4 Likes

@abcoathup what if we move this to the #general:guides-and-tutorials category? :slight_smile:

2 Likes

Updated to add a recipient contract.

1 Like

4 posts were split to a new topic: ERC777 events

A post was split to a new topic: ERC777 hooks

Good help, thank you very much

1 Like

I have updated to use OpenZeppelin Test Helpers 0.5

1 Like

A post was split to a new topic: Recipient error

A post was split to a new topic: Is there a simple ERC20 token example?

A post was split to a new topic: How to build a buyable ERC777?

A post was split to a new topic: In ERC777 example why are the token, recipient and sender contracts separate?

Hi! I followed this example to implement an ERC777 + ERC777 Recipient contract.

I’m having issues, deploying the recipient.

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

This call fails for some reason but I can’t figure out why.

This might be helpful - it’s the transaction in tenderly.

I can provide the code if tenderly isn’t enough :slight_smile:

Thanks in advance!

A post was split to a new topic: Warning: Could not decode event

Hi I'm trying to create a contract that will accept the UNI token and emit an event. I have setup metamask with an account which have few tokens and will transfer UNI token to my contract. I don't want to create any custom tokens.
I'm just using the implementation of IERC777Recipient piece from your example.

So within this code what must be passed to the constructor when I deploy the contract?

constructor (address token) public {
        _token = IERC777(**token**);     //what must be passed from remix here?

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

And will implementing just IERC777Recipient will be enough?

UNI is not an ERC777 token, so this will have no effect for receiving UNI token.

Continuing the discussion from Simple ERC777 token example:

In the contract Simple777Sender.sol what does the function _registerInterfaceForAddress(TOKENS_SENDER_INTERFACE_HASH, account) inside the sendFor function do? and where exactly is the function implemented?

Hi everyone! I have a really revolutionary project, and despite the fact that I am not a programmer, I try to nail down this code and learn in the process. But I am stuck because the existing code of the token (ERC20) must be changed to ERC777. The token script is this, ``` ...it sends some fixed part of every transaction to the "lottery" contracts, but as the smart contracts doesn't get notified and can't automatically do the action which is needed, I have to change the token to ERC777. Can anyone help me with this?

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol";

    contract Apros39 is ERC20 {
    using SafeMath for uint256;
    uint Royalty = 5;
    address public owner;
    //mapping(address => bool) public offRoyalty;
   

    constructor() ERC20("Apros39", "APROS39") {
    _mint(msg.sender, 10000* 10 ** 18);
    owner = msg.sender;
   // offRoyalty[msg.sender] == true;
}

    modifier onlyOwner(){
        require(msg.sender == owner);
        _;
}
    struct Destination {
    address payable lotteryAddress;
    string name;
}
    
    Destination[] public destinations;
  

    function addDestination(address payable lotteryAddress, string memory name) public onlyOwner {
    destinations.push(Destination(lotteryAddress, name));
    }
  


    function transfer(address recipient, uint256 amount) public override returns (bool) {
     uint royaltyFee = amount.mul(Royalty) / 100;
     for(uint i = 0; i < destinations.length; i++) {
       _transfer(_msgSender(), destinations[i].lotteryAddress, royaltyFee / destinations.length);
     }
       _transfer(_msgSender(), recipient, amount.sub(royaltyFee));
     
      return true;
     }
}`

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/ERC777.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol";

contract Apros78 is ERC777 {
using SafeMath for uint256;
address public owner;
uint Royalty = 5;
bytes32 constant public TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
event DoneStuff(address operator, address from, address to, uint256 amount, bytes userData, bytes operatorData);
//mapping(address => bool) public offRoyalty;
//event TransferReceived(address _from, uint _amount);

 constructor () ERC777("Apros78", "APO78", new address[](0)) {
    _mint(msg.sender, 1000000 * 10 ** 18, "", "");
    owner = msg.sender;
}
    modifier onlyOwner(){
    require(msg.sender == owner);
    _;

}

struct Destination {
address payable lotteryAddress;
string name;

}

Destination[] public destinations;
function addDestination(address payable lotteryAddress, string memory name) public onlyOwner {
destinations.push(Destination(lotteryAddress, name));

}

  function tokensToSend(address operator, address from, address to, uint256 amount,
    bytes calldata userData,
    bytes calldata operatorData
) public override returns (bool) {
uint royaltyFee = amount.mul(Royalty) / 100;
 for(uint i = 0; i < destinations.length; i++) {
  send(_msgSender(), destinations[i].lotteryAddress, royaltyFee / destinations.length);
 }
  send(_msgSender(), from, amount.sub(royaltyFee));
  emit DoneStuff(operator, from, to, amount, userData, operatorData);
  return true;
 }

}