Verify ERC721PresetMinterPauserAutoId deployed contract on rinkeby with Truffle needs help!

:computer: Environment

Truffle

:memo:Details

and successfully minted NFT (using OpenZeppelin Presets in the link above) on rinkeby, thank you so much for the tutorial!

Now, I needed to verify the deployed contracts on rinkeby, but since i was using presets, no code (only json) was provided. I found 2 other threads to help me:

I installed truffle-plugin-verify as outlined in this thread

npx truffle run verify ERC721PresetMinterPauserAutoId --network bsctestnet
Verifying ERC721PresetMinterPauserAutoId
Unexpected token u in JSON at position 0
Failed to verify 1 contract(s): ERC721PresetMinterPauserAutoId

but found out that i could not verify without the solidity source.

i then used the flattener on this thread (since im only npm install --save-dev @openzeppelin/contracts - no v3 as in the thread):

I managed to locate the source from ./node_modules/node_modules/@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol

I ran this command:
npx truffle-flattener ./node_modules/node_modules/@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol > ./contracts/FlatERC721PresetMinterPauserAutoId.sol

and hit this error:
npx: installed 64 in 12.022s
(node:35350) Warning: Accessing non-existent property ‘INVALID_ALT_NUMBER’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:35350) Warning: Accessing non-existent property ‘INVALID_ALT_NUMBER’ of module exports inside circular dependency
Error: None of the sub-resolvers resolved “node_modules/node_modules/@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol” location.
at ResolverEngine. (/Users/lucky/.npm/_npx/35350/lib/node_modules/truffle-flattener/node_modules/@resolver-engine/core/build/src/resolverengine.js:35:23)
at Generator.next ()
at fulfilled (/Users/lucky/.npm/_npx/35350/lib/node_modules/truffle-flattener/node_modules/@resolver-engine/core/build/src/resolverengine.js:4:58)

I am pretty much stuck using the programmatic means at this point. My next attempt will be to do this manually on Remix.

I post this here hopefully someone has a solution as truffle so far been very efficient in getting contract tested, and deployed.

Thanks!
:1234: Code to reproduce

See above

Try creating a file contracts/ERC721PresetMinterPauserAutoId.sol with an import:

import '@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol';

Then recompile, and then try to verify using truffle run verify.

1 Like

hi Frangio, thank you so much for the prompt reply.
I tried your suggestion, but still got the same error of unexpected token at position 0 at verify.

~/dev/eth-nft/contracts $ npx truffle compile

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/ERC721PresetMinterPauserAutoId.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /Users/lucky/dev/eth-nft/contracts/ERC721PresetMinterPauserAutoId.sol

,Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.8.0;"
--> /Users/lucky/dev/eth-nft/contracts/ERC721PresetMinterPauserAutoId.sol


> Everything is up to date, there is nothing to compile.

~/dev/eth-nft/contracts $ npx truffle run verify ERC721PresetMinterPauserAutoId --network rinkeby
Verifying ERC721PresetMinterPauserAutoId
Unexpected token u in JSON at position 0
Failed to verify 1 contract(s): ERC721PresetMinterPauserAutoId

Thanks again in advance for your help!
L

Hi @frangio

I finally got it working by deploying a new contract with your suggestion. thanks you so much.

here is what i did:
follow the instructions here by @abcoathup

instead of using presets (see Getting the contract artifacts section), don’t copy the build dir, instead use suggestion by @frangio above.

after you have completed all the steps in the tutorial, use this to verify (i used truffle). Another good source if you ran into issue using truffle-plugin-verify is to read the code in the repo (look up rkalis/truffle-plugin-verify in github…sorry, newbie only limited to 2 urls per post).

thx again for @frangio @abcoathup for their help, learn so much from your contribution.

Thanks!
L

2 Likes

Hi @luckydao . I am running into the same issue. I did what @frangio suggested but now I'm getting this error.

npx truffle console --network mumbai
truffle(mumbai)> migrate

Compiling your contracts...
===========================
> Compiling ./contracts/ERC721PresetMinterPauserAutoId.sol

@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.0;
^---------------------^

Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.8.0".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Here's how my contracts/ERC721PresetMinterPauserAutoId.sol looks like. Do I need to add anything to this solidity file?

import '@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol';

Just like the error message, the compiler version in your local environment 0.5.16 does not match your contract compiler version 0.8.x, I think you can set a right config in the truffle-config.js, for more details, you can have at here: https://www.trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration

Hi @Skyge I did like you said and added the compiler section on truffle-config.js. Now when I go through the migrate contract deployment phase, I get out of gas error. I have enough MATIC on my wallet. It looks like I have consumed the max 4 million gas limit.

Failed transaction id:

Here's the local error message:

npx truffle console --network mumbai
truffle(mumbai)> migrate

Compiling your contracts...
===========================
> Compiling ./contracts/ERC721PresetMinterPauserAutoId.sol
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /Users/saurav/mynft7/contracts/ERC721PresetMinterPauserAutoId.sol

,Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.8.6;"
--> /Users/saurav/mynft7/contracts/ERC721PresetMinterPauserAutoId.sol


> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'mumbai'
> Network id:      80001
> Block gas limit: 20000000 (0x1312d00)


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

   Deploying 'ERC721PresetMinterPauserAutoId'
   ------------------------------------------
   > transaction hash:    0xbc81777f7cbf4f517df4e70b6ddab5b5559c8ae0b9087e3e56ecb82628561dfd

Error:  *** Deployment Failed ***

"ERC721PresetMinterPauserAutoId" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  20000000 (0x1312d00)
   * Gas sent:     4000000 (0x3d0900)

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:74:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:228:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:140:1)
- Fetching solc version list from solc-bin. Attempt #1
- Fetching solc version list from solc-bin. Attempt #1
- Blocks: 0            Seconds: 0

any tips on how to fix this error?

Not sure, this can be caused by a number of reasons, such as your code size is too large, so you can increase the gas limit to deploy, or maybe there is something wrong in your constructor function.