ERC777 Migration with Truffle doesn't work

Hi team,
I’m a begginer in smart contracts programming and I’m having trouble deploying my ERC777 contract following the SimpleERC777 example. Could you please give me some hints ? I’ve been trying for hours but I don’t know if it come from my contract itself, my deployement file, my network (ganache), my config WSL2…
(In my opinion it’s a problem related to test-helpers dependencies access after runing npm. I think the require statement in my deploy file can not be found.)

I read the different discussions on “the ERC777 example” + “ERC777 constructor arguments” + “Deployment of ERC777 with Truffle Migrations doesn’t work” but I couldn’t solve my problem.

Thanks a lot for your time and your help

:computer: Environment

WSL2
Ganache GUI
Truffle v5.1.27 (core: 5.1.27)
Solidity - 0.6.2 (solc-js)
Node v14.3.0
Web3.js v1.2.1

:memo:Details

truffle migrate

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'ganache'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


2_deploy.js
===========

   Deploying 'QlayToken'
   ---------------------

Error:  *** Deployment Failed ***

"QlayToken" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at /home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:364:1
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Migration._deploy (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:70:1)
    at Migration._load (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:57:1)
    at Migration.run (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:167:1)
    at Object.runMigrations (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:148:1)
    at Object.runFrom (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.run (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
    at runMigrations (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:253:1)
    at /home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:218:1
Truffle v5.1.27 (core: 5.1.27)
Node v14.3.0

:1234: Code to reproduce

:scroll: My token contract

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
/**
 * @title QlayToken
 * @dev Very simple ERC777 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` or `ERC777` functions.
 * Based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/examples/SimpleToken.sol

 */
contract QlayToken is ERC777 {
    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor () public ERC777("QlayToken", "MIM", new address[](0)) {
        _mint(msg.sender, 10000 * 10 ** 18, "", "");
    }
}

:scroll: My migration

 const QlayToken = artifacts.require('QlayToken');

require('@openzeppelin/test-helpers/configure')({ provider: web3.currentProvider, environment: 'truffle' });

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

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

  await deployer.deploy(QlayToken);
};
1 Like

Hi @hydris-bessa,

I am using WSL2, ganache-cli and the following:

$ npx truffle version
Truffle v5.1.27 (core: 5.1.27)
Solidity - 0.6.7 (solc-js)
Node v10.19.0
Web3.js v1.2.1

I suspected the issue was node v14.3 but I just used nvm to change to node v14.3 and could migrate ok. I normally use node v10 as the ecosystem has had trouble in the past with the latest versions of node.

$ npx truffle version
Truffle v5.1.27 (core: 5.1.27)
Solidity - 0.6.7 (solc-js)
Node v14.3.0
Web3.js v1.2.1

This was my migrate using your deploy.js and contract.

$ npx truffle migrate

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/QlayToken.sol
> Compiling @openzeppelin/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts/introspection/IERC1820Registry.sol
> Compiling @openzeppelin/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC777/ERC777.sol
> Compiling @openzeppelin/contracts/token/ERC777/IERC777.sol
> Compiling @openzeppelin/contracts/token/ERC777/IERC777Recipient.sol
> Compiling @openzeppelin/contracts/token/ERC777/IERC777Sender.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Artifacts written to /home/abcoathup/projects/forum/luckytoken/build/contracts
> Compiled successfully using:
   - solc: 0.6.7+commit.b8d736ae.Emscripten.clang



Starting migrations...
======================
> Network name:    'development'
> Network id:      1590640465913
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x0241d755e58d08599e42d8f2e2985bd8ba4c3c92ada749507cfd8e36eb30832b
   > Blocks: 0            Seconds: 0
   > contract address:    0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb
   > block number:        7
   > block timestamp:     1590640774
   > account:             0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
   > balance:             99.85672596
   > gas used:            164379 (0x2821b)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00328758 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00328758 ETH


2_deploy.js
===========

   Deploying 'QlayToken'
   ---------------------
   > transaction hash:    0x2dece652fcb181c14dfc4be674606ed1483225864af971caca8e2e08a2ee5ea6
   > Blocks: 0            Seconds: 0
   > contract address:    0xe982E462b094850F12AF94d21D470e21bE9D0E9C
   > block number:        9
   > block timestamp:     1590640777
   > account:             0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
   > balance:             99.8005739
   > gas used:            2765262 (0x2a31ce)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.05530524 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.05530524 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.05859282 ETH

Please ask all the questions that you need. I have been in your situation many times.

Your contract and migrations script are ok.

Can you try using ganache-cli instead?
I tried with Ganache GUI but was having issues connecting on WSL2 that I need to look into.

Thank you for your reply @abcoathup.
I’ve tried using ganache-cli before but I have an error message (below). That is why I decided to use Ganache GUI.

 hydris  LAPTOP-JPBVRK0A  ~  code  qlay-token   master  $   ganache-cli
Ganache CLI v6.9.1 (ganache-core: 2.10.2)
Error: Callback was already called.
    at /home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:17:276
    at s.<anonymous> (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:17:2238)
    at s.emit (events.js:315:20)
    at s.destroy (/home/hydris/.nvm/versions/node/v14.3.0/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:712589)
    at finish (_stream_writable.js:658:14)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I’ve also tried to change my node version with nvm and use Node v10.19.0 :
2_deploy.js
===========

   Deploying 'QlayToken'
   ---------------------

Error:  *** Deployment Failed ***

"QlayToken" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.26 (core: 5.1.26)
Node v10.19.0 

I’ve tried to check for this file “deployement.js” but I can’t find it…

cd /usr/local/lib/node_modules/truffle/build
 hydris  LAPTOP-JPBVRK0A  usr  local  …  node_modules  truffle  build    $    ls
Assert.sol                     AssertBool.sol          AssertIntArray.sol   OldSafeSend.sol           cli.bundled.js
AssertAddress.sol              AssertBytes32.sol       AssertString.sol     analytics.bundled.js      cli.bundled.js.map
AssertAddressArray.sol         AssertBytes32Array.sol  AssertUint.sol       analytics.bundled.js.map  library.bundled.js
AssertAddressPayableArray.sol  AssertGeneral.sol       AssertUintArray.sol  chain.bundled.js          library.bundled.js.map
AssertBalance.sol              AssertInt.sol           NewSafeSend.sol      chain.bundled.js.map      templates

Also, I’m using Windows terminal to run all my commands.

These are my hypothesis :
1 - TRUFFLE INSTALLING PROBLEM
There is no file deployement.js existing on my WSL -> Maybe a probleme while installing truffle ? (after reinstall it, nothing changed)
2 - WSL PATH
There is a problem related to my path - (I don’t have the linux Icon on my windows file explorer though)

  • My starting directory from my Windows Terminal (Ubuntu) is //wsl$/Ubuntu/home/hydris
  • The original one was /mnt/<drive>/<path>

I might unsintall and install WSL

What do you think ? (thanks for your time)

1 Like

Hi @abcoathup,
I come back because I still haven't found the answer to my problem...
Both my assumptions are wrong. I've reinstalled WSL so it's not that.
I managed to use ganache-cli, but that doesn't solve anything.
If you have any advice... it would help me a lot.

1 Like

Hi @hydris-bessa,

I'm sorry to hear that you are still having issues. I fully appreciate how frustrating this can be.

I recommend using a node version manager to change node to node 10.
Looking at the ganache-cli repository there is an open issue with node 14: https://github.com/trufflesuite/ganache-cli/issues/732

I assume that you used an earlier version of node (than node 14). What was the error that you had when trying to migrate?

Would you mind sharing a repository or your current contract, migrations script and your current versions of node, npm, truffle that you are using. (If you use npx truffle version this will give you these).

Hi,

I used nvm to change my node version from 14.3 to 10.19 -> The result is : I have less errors but still one.

2_deploy.js
===========

   Replacing 'QlayToken'
   ---------------------

Error:  *** Deployment Failed ***

"QlayToken" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at /home/hydris/.nvm/versions/node/v10.19.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.28 (core: 5.1.28)
Node v10.19.0

Here, You’ll find my repository : https://github.com/hydris-bessa/ERC777

here is my version :

hydris@LAPTOP-TS5J0JFU:~/codetest/test_qlay$ npx truffle version
Truffle v5.1.28 (core: 5.1.28)
Solidity - 0.6.7 (solc-js)
Node v10.19.0
Web3.js v1.2.1

Also, I’ve tried to use Remix IDE to have an other point of view. I can successfully compile but I still can’t migrate for some reasons. I believe there is a problem in the structure of my token contract (which is the SimpleERC777)

What do you think ?

Hi,

I figured out the solution and I’m a little disappointed ahah.
It’s a bad configuration of my ganache connection… So I modified the truffle-config file to match with ganache…

Thanks a lot for your help.

1 Like

Hi @hydris-bessa,

Great news. Glad you were able to resolve.

Running ganache-cli -d then truffle-config.js can just have a development network section.

    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 8545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
1 Like

Hi @hydris-bessa,

If you have a moment, it would be great if you could Introduce yourself here!