繁体   English   中英

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

[英]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> 

这是我的 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应该是合同的名称,而不是文件的名称

请确保您将多边形扫描 api 键放在小写字母中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM