Error deploying simple ERC777 contract with Truffle and Ganache

:computer: Environment

Truffle v5.0.38 (core: 5.0.38)
Node v10.16.3
OpenZeppelin 2.3
MacOS Catalina 10.15

:memo:Details

When deploying on Ganache a simple ERC777 contract implementation, it returns this error:

Error: Error: Error: Invalid JSON RPC response: ""
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:96:1)

:1234: Code to reproduce

Contract code:

pragma solidity ^0.5.0;
import '@openzeppelin/contracts/token/ERC777/ERC777.sol';
contract TokenWithProofOfReserve is ERC777 {
    constructor (
        string memory name,
        string memory symbol,
        uint256 initialSupply)
        public ERC777(name, symbol,  new address[](0))
    {
        _mint(msg.sender, msg.sender, initialSupply * 10 ** 18, "", "");
    }
}

Deploy contracts file:

const TokenWithProofOfReserve = artifacts.require("TokenWithProofOfReserve");

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

module.exports = async function(deployer, network, accounts) {     
        const registry = await singletons.ERC1820Registry(accounts[0]);
        await deployer.deploy(TokenWithProofOfReserve, "MyToken", "MTK",  10000 );
};
1 Like

I'm not certain that third argument to ERC777, new address, is correct.

1 Like

You are right, it is new address[](0), sorry I did not copy it correctly. But the deployment problem is the same, the contract compiles with Truffle correctly, but then there is the problem at deployment time.

Thanks for pointing to the typo.

1 Like

But is that right? Can you just create a new 'address' array like that? Even if you can, what are you trying to achieve?

I've just my own ERC777 token, and that third argument is for default operators. I pass in the address of the contract that manages supply there...

1 Like

Just got it from this post, so I assumed (maybe wrongly) that it was correct:

I will try to change it just for the case that is the problem, thanks!

1 Like

Update: Just included the defaultOperators argument, and the sams deployment error occurs.

1 Like

Just got it from this post

Ah, then it is probably right. Forgive me - my token constructor accepts an address, which I pass in.

I should really fire suggestions off after trying them myself, but rather than this:

const registry = await singletons.ERC1820Registry(accounts[0]);

I do this:

await singletons.ERC1820Registry(accounts[0]);
1 Like

Also, I assume Ganache is running, and it’s configured to match your truffle-config.js config’? I had to change Ganache to run on port 8545. And my truffle-config.js looks like this:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*",
      gasPrice: 0x1,
      gas: 4612388
    }
  },
  compilers: {
    solc: {
      version: "0.5.7"
    }
  }
};

My deployer also includes this:

try {

  require("openzeppelin-test-helpers/configure")({ web3 })

} catch (e) {
  // If deploying to a testnet, a weird error about configuring web3 twice occurs. Wrapping the function in a try-catch
  // until we find a better approach or --skipDryRun is added to truffle in the next major release
  // console.error(e);
}

Forgive me if none of that helps…

1 Like

Many thanks. I tried to change solc version as I had another one and recompile but no luck. So far no way of deploying the contract :frowning:

1 Like

Hi @msicilia,

Welcome to the community :wave:

I was able to deploy your TokenWithProofOfReserve token to ganache-cli using your migrations script and interact with it using truffle console. Though I am running Windows Subsystem for Linux rather than a Mac.

I suggest you try deploying a simple contract to ganache-cli to rule out any issues with deployment.

Below is a simple contract and migrations script that you could try.

Start a local blockchain
ganache-cli -d

Counter.sol

pragma solidity ^0.5.0;

contract Counter {
  uint256 public value;

  function increase() public {
    value++;
  }
}

2_deploy.js

const Counter = artifacts.require("Counter");

module.exports = function(deployer) {
  deployer.deploy(Counter);
};
1 Like

Many thanks!
Everything works ok for us with other, non-ERC777 libraries or code, this is why I thought it was something related to testing and the registry specific to the ERC777 library.

But if you were able to deploy with Truffle/Ganache and use the same code, then it should be something related to our install or some Mac-specific issue. We’ll revise that, thanks again!

1 Like

Hi @msicilia,

Let me know if I can help track down the issue.

I would try deploying a simple contract (even an OpenZeppelin ERC20 token) from the same project to rule out any config/environment issues e.g. https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/examples/SimpleToken.sol

Hi @msicilia,

Just checking in to see if you resolved?

For the latest version of @openzeppelin/test-helpers

OpenZeppelin Test Helpers 0.5 - #3 by abcoathup
As per how to upgrade from 0.4 I needed to change in my migrations ( 2_deploy.js )

require('@openzeppelin/test-helpers/configure')({ web3 });

to

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

Yes, resolved, thank you. It was probably a problem with older versions of the libraries, as I reinstalled all from scratch and it worked.

1 Like

Hi, I am running into exact same issue, not sure if there was clear conclusion what is the issue,
In my case I am able to deploy ERC777 contract to ganache as a part of truffle test suite, but fail to do it with pure web3 deploy script.