How and why does ERC777 need ERC1820

I’m kinda struggling with this, too - I’ll get there, but some clear docs as to how and why I need to use ERC1820 with an ERC777 token, and how to deploy to Ganache and Rinkeby, using truffle, would be very much appreciated and save me and others alike many hours of ‘interesting’ work :wink:

1 Like

Okay, for anyone else struggling, here are some details as to how I managed to deploy an ERC777 contract to Ganache, using Truffle.

First, install openzeppelin-test-helpers and chai:

npm install --save-dev openzeppelin-test-helpers chai

Secondly, modify migrations/2_deploy_contracts.js so it registers your default account with ERC1820Registry. My deploy script looks like this:

const StandardToken = artifacts.require("./StandardToken.sol");

require('openzeppelin-test-helpers/configure')({ web3 });
const { singletons } = require('openzeppelin-test-helpers');

module.exports = async function (deployer, network, accounts) {

  console.log("Default account ", accounts[0]);

  if (network === 'development')  {
    // In a test environment an ERC777 token requires deploying an ERC1820 registry
    await singletons.ERC1820Registry(accounts[0]);

  await deployer.deploy(StandardToken, 4881174811, []);
  const token = await StandardToken.deployed();
  console.log("Token address:", token.address);

Finally, compile and migrate your contract; something along the likes of this:

truffle compile --all && truffle migrate --network development

Good luck!


Hi @glowkeeper

The Simple ERC777 token example shows how to deploy ERC1820 for a local testnet (e.g. ganache-cli). Let me know if something is missing or needs more detail and I can update the example.

ERC1820 is deployed to all public networks ( so you don’t need to deploy it for public testnets such as Rinkeby or Ropsten. You only need to deploy it to local testnets (e.g. ganache-cli) or private networks. (Your migrations script appears to try to deploy for Rinkeby or Ropsten).

ERC1820 is used in the hooks functionality of ERC777, see the documentation for more detail:

Let me know if you need more information on the why and I can try to dig a little deeper.

1 Like

ooo - thanks @abcoathup - I wasn’t aware of that - so as not to confuse anyone else stumbling across this post, I have removed the Ropsten and Rinbkeby references…

1 Like