Sumit Sharma
Sumit Sharma

Reputation: 93

How to verify polygon smart contract using truffle?

I deployed a simple NFT smart contract on polygon mumbai testnet but when I am trying to verify it then It is showing an error. please guide me how to verify it...

This is the error which I am getting

PS C:\Users\Sumits\Desktop\truffle> truffle run verify MyNFT  --network matic --debug
DEBUG logging is turned ON
Running truffle-plugin-verify v0.5.20
Retrieving network's chain ID
Verifying MyNFT
Reading artifact file at C:\Users\Sumits\Desktop\truffle\build\contracts\MyNFT.json
Failed to verify 1 contract(s): MyNFT
PS C:\Users\Sumits\Desktop\truffle> 

This is my truffle-config.js

const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    matic: {
      provider: () => new HDWalletProvider(mnemonic, `https://rpc-mumbai.maticvigil.com`),
      network_id: 80001,
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },
  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },
  // Configure your compilers
  compilers: {
    solc: {
      version: "^0.8.0",
    }
  },
  plugins: ['truffle-plugin-verify'],
  api_keys: {
    polygonscan: 'BTWY55K812M*******WM9NAAQP1H3'
  }
}

Upvotes: 1

Views: 1513

Answers (2)

Ritanshu Singh
Ritanshu Singh

Reputation: 1

please make sure you are putting the polygonscan api key in lowercase

Upvotes: 0

Yilmaz
Yilmaz

Reputation: 49551

First deploy the contract:

truffle migrate --network matic --reset

I am not sure if you successfully deploy it to matic network, because your configuration does not seem to be correct:

matic: {
      // make sure you set up provider correct
      provider: () => new HDWalletProvider(mnemonic, `https://rpc-mumbai.maticvigil.com/v1/YOURPROJECTID`),
      network_id: 80001,
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    },

Then verify.

truffle run verify ContractName --network matic

ContractName should be the name of the contract, not the name of the file

Upvotes: 1

Related Questions