truffle-plugin-verify icon indicating copy to clipboard operation
truffle-plugin-verify copied to clipboard

Cannot find module '@openzeppelin/contracts/GSN/Context.sol'

Open sudojanuc opened this issue 4 years ago • 38 comments
trafficstars

Hello, whenever i try to verify my ERC721 Contract I get the error message: "Cannot find module '@openzeppelin/contracts/GSN/Context.sol'".

I am using the openzeppelin library (installed via npm install).

My SmartContract starts like this:

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";

contract ChallengeManager is LockFactory, ERC721, Ownable {
...

The ERC721 Contract has a dependency to the requested "Context.sol" Contract.

I also tried to import "@openzeppelin/contracts/GSN/Context.sol" on my ChallengeManager Contract, but i still get the same Error.

sudojanuc avatar Sep 07 '21 18:09 sudojanuc

I think Ownable is under import "@openzeppelin/contracts/access/Ownable.sol";.

d-sfounis avatar Sep 09 '21 09:09 d-sfounis

Thanks for the reply. The issue is definitely coming from the ERC721 import. I already removed the Ownable part and still got the same fault. But I can verify it if i remove the ERC721 import.

By the way, I forgot to mention that im using version "2.5.1" of the openzeppelin library. Maybe this explains the difference in the import. I have to use this version, because I am using another library which is wirtten in solidity version 5.17.

sudojanuc avatar Sep 09 '21 12:09 sudojanuc

Do you have your code repository available somewhere to check out what might be the issue? Also what OS are you using?

rkalis avatar Sep 09 '21 12:09 rkalis

Yes, thats the contract I'm trying to verify: https://github.com/sudojanuc/fitness-challenge/blob/main/contracts/ChallengeManager.sol

Contract address (rinkeby): 0x4D70519d63158e7be67c1B9B01C4b126039805FB

I am using Windows 10, but i also failed on Linux.

sudojanuc avatar Sep 09 '21 12:09 sudojanuc

I might have run into a similar issue. "Cannot find module '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'" I am using @openzeppelin/[email protected]

D23randomized avatar Sep 10 '21 23:09 D23randomized

Did anyone sort this issue out I seem to be running into a very similar issue "Cannot find module '@openzeppelin/"

Would love some help with this one.

my process is:

  • mkdir newContact

  • cd newContact

  • npm init -y

  • truffle init

  • npm install @openzeppelin/contracts

  • npm install truffle-plugin-verify

  • yarn add -d truffle-plugin-verify (this gives a small error)

  • warning ../../../package.json: No license field error Missing list of packages to add to your project.

  • Add all necessary code (.js and .sol)

  • truffle compile (code compiles fine)

  • truffle migrate --network rinkeby (code deploys fine)

  • truffle run verify NewTest --network rinkeby --debug (code below)

werksone avatar Sep 17 '21 07:09 werksone

Truffle debug output:

DEBUG logging is turned ON
Running truffle-plugin-verify v0.5.15
Verifying NewTest
Reading artifact file at /Users/***/Documents/tst/newTest/build/contracts/NewTest.json
Retrieving constructor parameters from https://api-rinkeby.etherscan.io/api?apiKey=FCCUFVZVZCN462K616Q6WCVJI4FNRMMTEX&module=account&action=txlist&address=0x5a1a3b04e98Cb8845cc4ADe0274FA7A991F6000f&page=1&sort=asc&offset=1
Constructor parameters retrieved: 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000e7777772e6675636b79612e636f6d000000000000000000000000000000000000
Cannot find module '@openzeppelin/contracts/utils/introspection/IERC165.sol'
Require stack:
- /usr/local/lib/node_modules/truffle-plugin-verify/verify.js
- /usr/local/lib/node_modules/truffle/node_modules/original-require/index.js
- /usr/local/lib/node_modules/truffle/build/cli.bundled.js
Failed to verify 1 contract(s): NewTest

package.json:

  "name": "newTest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@openzeppelin/contracts": "^4.3.2",
    "@openzeppelin/test-helpers": "^0.5.13",
    "truffle-plugin-verify": "^0.5.3"
  }
}

truffle-config.js:

module.exports = {

  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    rinkeby: {
      host: "localhost", // Connect to geth on the specified
      port: 8545,
      from: "***", // default address to use for any transaction Truffle makes during migrations
      network_id: 4,
      gas: 5000000 // Gas limit used for deploys
    }
  },

  compilers: {
    solc: {
      version: "0.8.0",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },
  plugins: [
    'truffle-plugin-verify'
  ],
  api_keys: {
    etherscan: "***"
  }
};

werksone avatar Sep 17 '21 07:09 werksone

Same issue here - https://github.com/rkalis/truffle-plugin-verify/issues/117

Not resolved yet

eulerbeat5 avatar Nov 23 '21 03:11 eulerbeat5

To anyone experiencing this issue: what version of Node are you running?

rkalis avatar Dec 06 '21 08:12 rkalis

same issue, I can not verify the contracts where I used the openzeppelin library (Context.sol)

romuloags avatar Dec 14 '21 23:12 romuloags

I'm using v14.17.5 (node.)

romuloags avatar Dec 14 '21 23:12 romuloags

Any reproduction repos?

rkalis avatar Dec 15 '21 16:12 rkalis

sure. https://github.com/romuloags/redCriptoPay/tree/testnet I deployed my contracts on ropsten , I have only been able to verify 1 contract (the one doesn't have openzeppelin library)

romuloags avatar Dec 16 '21 14:12 romuloags

Thanks for providing the repo. When I ran npm install and tried to verify I got some other error messages which were resolved after upgrading the plugin from 0.5.3 to 0.5.20.

From there I have tried to reproduce this issue with a lot of different configurations (any combination of using Node 12/14 and NPM 6/7/8/Yarn), but I wasn't able to reproduce it.

@romuloags what OS and Truffle version are you running? And is there anything else that you can think of that might be relevant?

rkalis avatar Dec 16 '21 16:12 rkalis

I'm using WSL2 Ubuntu 20.04.2 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64) npm: '6.14.14', Truffle v5.4.7 (core: 5.4.7) Solidity v0.5.16 (solc-js) Node v14.17.5 Web3.js v1.5.2

romuloags avatar Dec 17 '21 20:12 romuloags

Could you just try updating to the latest Truffle (npm install -g truffle@latest) and retry the process? That's the only thing that I can think of atm.

rkalis avatar Dec 18 '21 14:12 rkalis

It did not work.

romuloags avatar Dec 20 '21 19:12 romuloags

I decided to copy and paste OpenZeppelin libraries directly in the contracts, and it worked just fine. even though you have to do this and can be kind of annoying, this plugin really helps to verify the contracts faster and easier than directly from etherscan. thanks for the help though.

romuloags avatar Dec 20 '21 23:12 romuloags

I have the same issue but with a package that is local (bootstrapped with lerna) instead of OpenZeppelin.

npm: 7.17.0 node: 14.15.1 truffle: 5.4.26 truffle-plugin-verify: 0.5.20 solidity: 0.8.6

hasandogu avatar Dec 24 '21 19:12 hasandogu

Been dealing with the same issue, seems like you have to have the truffle-config.js and package.json in the same directory, for example, mine is within the src directory for my project. This is bad practice but works with no errors. Also, truffle-plugin-verify does not work for the rinkeby test net from what I can tell.

nicknovoa03 avatar Jan 11 '22 17:01 nicknovoa03

@nicknovoa03 do you have a repo with the config where it doesn't work for you that I can look at?

rkalis avatar Jan 15 '22 21:01 rkalis

cp -r node_modules/@openzeppelin contracts then run verify works for me

script-money avatar Jan 18 '22 21:01 script-money

That's interesting @script-money, do you have a repo where I can reproduce this issue?

rkalis avatar Jan 20 '22 19:01 rkalis

That's interesting @script-money, do you have a repo where I can reproduce this issue?

https://github.com/script-money/blockchain-developer-bootcamp-final-project

script-money avatar Jan 22 '22 18:01 script-money

I can't reproduce the issue on that repository. People with this issue, please provide your OS, Truffle version, Node version, and NPM/Yarn version in the comments to figure out common things between the people with these issues.

rkalis avatar Jan 23 '22 11:01 rkalis

cp -r node_modules/@openzeppelin contracts then run verify works for me

macOS big Sur 11.6 Truffle v5.4.15 (core: 5.4.15) Node v14.17.6 yarn version v1.22.10 truffle-plugin-verify v0.5.20

script-money avatar Jan 26 '22 15:01 script-money

😅 so it looks like we have people experiencing this issue with Windows/Mac/Linux, both with Yarn and NPM, so it doesn't look like there's anything you guys have in common . But at the same time the majority of people (including myself) don't have this issue. I'm stumped.

rkalis avatar Jan 27 '22 11:01 rkalis

It has been deprecated in the latest version. https://github.com/OpenZeppelin/openzeppelin-contracts/issues/2520

exbucks avatar Jan 28 '22 01:01 exbucks

I ran into this issue as well, truffle compile worked ok, and migrate worked as well. But when I tried test the openzeppelin artifact files couldn't be found by the resolver.

I noticed the openzeppelin contracts were not listed in the compilation logs for test

Then I did truffle test --compile-all and that fixed it. Subsequent runs of truffle test without the --compile-all flag work as well now.

Dropping this here in hopes this helps someone get past this quicker than I did.

dherbst avatar Apr 19 '22 15:04 dherbst

This issue happens when you want to use an older version of SDKs with a newer version and mixing all. To prevent this to happen, try using the same version or updating SDK versions from node_modules. This always works and it's better to use the latest version :)

Fabbiya avatar Aug 02 '22 07:08 Fabbiya