如何使用松露验证多边形智能合约?

How to verify polygon smart contract using truffle?

我在多边形孟买测试网上部署了一个简单的 NFT 智能合约,但是当我尝试验证它时它显示错误。请指导我如何验证它...

这是我遇到的错误

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> 

这是我的松露-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'
  }
}

首先部署合约:

truffle migrate --network matic --reset

我不确定你是否成功部署到matic网络,因为你的配置似乎不正确:

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
    },

然后验证。

truffle run verify ContractName --network matic

ContractName应该是合约名,不是文件名