Could not find method initialize with 0 arguments in contract

Hi,
I’m trying to create an upgradable instance of a simple contract following the guide here https://docs.zeppelinos.org/docs/deploying.html but when I try to create the instance with zos create MyContract --init initialize I get the following error Could not find method initialize with 0 arguments in contract
the simplified contract is the following


import "zos-lib/contracts/Initializable.sol";
import "openzeppelin-eth/contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-eth/contracts/token/ERC20/IERC20.sol";
import "./interfaces/CERC20Token.sol";

contract MyContract is Initializable {
  using SafeERC20 for IERC20;

  address public owner;
  address public cDAI;
  address public DAI;

  function initialize() initializer public {
    owner = 0x...;
    cDAI = 0x...;
    DAI = 0x...;
  }
}

is there anything wrong? I tried both on rinkeby and in a local ganache instance but with the same error.

Thank you

1 Like

Hi, for what I can tell you are not declaring the variables to be pass to the initialize function. As follows:

function initialize(address _owner, address _cDAI, address DAi) initializer public {
    owner = 0x...;
    cDAI = 0x...;
    DAI = 0x...;
  }

Also, remember to place the pragma solidity at the top of the contract.

Hope it helps.

2 Likes

Thank you for replying, but I’m using pragma solidity ^0.5.0; and the various 0x... represent some fixed addresses which are not passed as params in initialize method.

Hi @bugduino

I was able to create a similar contract and create on ganache following the guide

Using the following command (The --verbose flag gives more information.)
npx zos create MyContract --init initialize --verbose

Sample contract:

pragma solidity ^0.5.0;

import "zos-lib/contracts/Initializable.sol";
import "openzeppelin-eth/contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-eth/contracts/token/ERC20/IERC20.sol";
//import "./interfaces/CERC20Token.sol";

contract MyContract is Initializable {
  using SafeERC20 for IERC20;

  address public owner;
  address public cDAI;
  address public DAI;

  function initialize() initializer public {
    owner = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
    cDAI = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
    DAI = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359;
  }
}

Can you supply the CERC20Token.sol interface so I can reproduce as that appears to be the only difference?

Otherwise please run again with --verbose and provide the output as well as your ZeppelinOS version npx zos --version so we can investigate a bit further.

1 Like

Some more info @abcoathup (I removed the CERC20 interface too, but same error)

    ↑1 Projects/ethereal git:(feature/add-DAI) ▶ zos --version
    2.2.3
    Ξ Projects/ethereal git:(feature/add-DAI) ▶ zos create MyContract --init initialize --verbose    
    [Session] Using session with network local, sender address 0x....., timeout 600 seconds
    [ZWeb3] WARNING: Address 0x..... is not checksummed. Consider checksumming it to avoid future warnings or errors.
    [ProxyAdmin] Deploying new ProxyAdmin...
    [ProxyAdmin] Deployed ProxyAdmin at 0x.....
    [Error] Error: Could not find method initialize with 0 arguments in contract MyContract
        at tryGetFunctionNodeFromMostDerivedContract (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/utils/ABIs.js:75:11)
        at tryGetTargetFunction (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/utils/ABIs.js:50:24)
        at getABIFunction (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/utils/ABIs.js:26:26)
        at Object.buildCallData (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/utils/ABIs.js:19:20)
        at ProxyAdminProject._getAndLogInitCallData (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/project/BaseSimpleProject.js:130:61)
        at ProxyAdminProject.<anonymous> (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/project/BaseSimpleProject.js:83:39)
        at Generator.next (<anonymous>)
        at fulfilled (/home/bugman/.asdf/installs/nodejs/10.15.0/.npm/lib/node_modules/zos/node_modules/zos-lib/lib/project/BaseSimpleProject.js:4:58)
        at process._tickCallback (internal/process/next_tick.js:68:7)

I noticed that generally I’m using zos directly and not via npx, could this be a problem?

I simplified the contract to the bare minimum:

pragma solidity ^0.5.0;

import "zos-lib/contracts/Initializable.sol";

contract Pragma is Initializable {
  address public cDAI;

  function initialize() initializer public {
    cDAI = 0x6D7F0754FFeb405d23C51CE938289d4835bE3b14;
  }
}

and removed all zos.* files to start from scratch, but got a slightly different error:

Ξ Projects/ethereal git:(feature/add-DAI) ▶ npx zos --version                                                                                                                                    [2/1781]
2.2.3                                                                                                       
Ξ Projects/ethereal git:(feature/add-DAI) ▶ npx zos init Pragma
Created zos.json                            
Ξ Projects/ethereal git:(feature/add-DAI) ▶ npx zos add Pragma
Compiling contracts with Truffle...

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Pragma.sol
> Compiling zos-lib/contracts/Initializable.sol
> Artifacts written to /home/bugman/Projects/ethereal/client/src/contracts
> Compiled successfully using:
   - solc: 0.5.0+commit.1d4f565a.Emscripten.clang


Adding Pragma
Updated zos.json
Ξ Projects/ethereal git:(feature/add-DAI) ▶ zos session --network local --from 0x1df62f291b2e969fb0849d99d9ce41e2f137006e --expires 3600
↑130 Projects/ethereal git:(feature/add-DAI) ▶ npx zos session --network local --from 0x1df62f291b2e969fb0849d99d9ce41e2f137006e --expires 3600
Using network local, sender address 0x1df62f291b2e969fb0849d99d9ce41e2f137006e by default.
Ξ Projects/ethereal git:(feature/add-DAI) ▶ npx zos push
Compiling contracts with Truffle...

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Pragma.sol
> Compiling zos-lib/contracts/Initializable.sol
> Artifacts written to /home/bugman/Projects/ethereal/client/src/contracts
> Compiled successfully using:
   - solc: 0.5.0+commit.1d4f565a.Emscripten.clang


Using session with network local, sender address 0x1df62f291b2e969fb0849d99d9ce41e2f137006e, timeout 600 seconds
WARNING: Address 0x1df62f291b2e969fb0849d99d9ce41e2f137006e is not checksummed. Consider checksumming it to avoid future warnings or errors.
Validating contract Pragma
Uploading Pragma contract as Pragma
Deploying logic contract for Pragma
Created zos.dev-1557822768822.json
Ξ Projects/ethereal git:(feature/add-DAI) ▶ npx zos create Pragma --init initialize --verbose
[Session] Using session with network local, sender address 0x1df62f291b2e969fb0849d99d9ce41e2f137006e, timeout 600 seconds
[ZWeb3] WARNING: Address 0x1df62f291b2e969fb0849d99d9ce41e2f137006e is not checksummed. Consider checksumming it to avoid future warnings or errors.
[ProxyAdmin] Deploying new ProxyAdmin...
[ProxyAdmin] Deployed ProxyAdmin at 0xFA33c8EF8b5c4f3003361c876a298D1DB61ccA4e
[Error] Error: Found more than one match for function initialize with 0 arguments in contract Pragma
    at tryGetFunctionNodeFromMostDerivedContract (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/utils/ABIs.js:72:28)
    at tryGetTargetFunction (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/utils/ABIs.js:50:24)
    at getABIFunction (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/utils/ABIs.js:26:26)
    at Object.buildCallData (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/utils/ABIs.js:19:20)
    at ProxyAdminProject._getAndLogInitCallData (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/project/BaseSimpleProject.js:130:61)
    at ProxyAdminProject.<anonymous> (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/project/BaseSimpleProject.js:83:39)
    at Generator.next (<anonymous>)
    at fulfilled (/home/bugman/Projects/ethereal/node_modules/zos-lib/lib/project/BaseSimpleProject.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I wouldn't expect a difference in behavior between installing zos globally or installing locally and running with npx zos

@bugduino I started from scratch following the guide but using the Pragma contract you supplied and didn’t get any issues.

One thing I noticed is that you call npx zos init Pragma when the parameter is the name of the directory rather than the contract, though that shouldn’t be an issue.

You appear to create a session with global zos zos session --network local --from 0x1df62f291b2e969fb0849d99d9ce41e2f137006e --expires 3600 and then with the local zos zos session --network local --from 0x1df62f291b2e969fb0849d99d9ce41e2f137006e --expires 3600

Would you be able to share your code in a repository in GitHub or the like?
I want to be able to reproduce the error that you are seeing.

1 Like

I tried starting a project from scratch and it all went well, so I tried once more in the previous project after deleting the Pragma artifact and it went through. I’m unable to reproduce it at the moment, it was probably due to some artifact mismatching I suppose.

2 Likes