You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Truffle验证Sepolia合约时遇Etherscan链ID支持错误的解决方法

解决Truffle验证Sepolia合约时的Etherscan网络支持错误

出现“Etherscan has no support for network sepolia with chain id 11155111”错误,核心原因是truffle-plugin-verify插件未正确识别Sepolia测试网的配置,以下是具体解决步骤:

  • 升级truffle-plugin-verify到最新版本
    旧版本插件可能未内置Sepolia测试网的链ID映射,执行命令完成升级:

    npm install truffle-plugin-verify@latest --save-dev
    # 或使用yarn
    yarn add truffle-plugin-verify@latest --dev
    
  • 手动指定Sepolia的Etherscan API地址
    如果升级后问题仍存在,在truffle-config.js的api_keys下方添加api_urls字段,明确指定Sepolia对应的Etherscan API端点,修改后的完整配置如下:

    const apikeys = require("./chains/apikeys");
    const keys = require("./keys.json");
    
    module.exports = { 
      
      plugins: ["truffle-plugin-verify"],
      api_keys:{
        etherscan: "myApiEtherScan"
      },
      // 添加Sepolia的API地址映射
      api_urls: {
        sepolia: "https://api-sepolia.etherscan.io/api"
      },
      contracts_build_directory: "./public/contracts",
      networks: {
        
         development: {
          host: "127.0.0.1",    
          port: 7545,            
         network_id: "*",     
         },
        sepolia: {
          provider: () => 
          new HDWalletProvider(
            keys.PRIVATE_KEY,
            keys.INFURA_SEPOLIA_URL,       
          ),
          network_id: 11155111,
          gas:5221975,
          gasPrice:20000000000,
          confirmations: 3,
          timeoutBlocks:200,
          skipDryRun: true
        }
      },
    
      compilers: {
        solc: {
          version: "0.8.16",
          settings: {
            optimizer: {
            enabled: true, // Default: false
            runs: 1000 // Default: 200
            }
            }       
        }
      },
    };
    
  • 确认API Key有效性
    检查api_keys中的Etherscan API Key是否正确有效,该Key可在Etherscan官网个人API页面生成,测试网与主网共用同一Key。

完成以上操作后,重新执行合约验证命令即可:

truffle run verify YourContractName --network sepolia

内容的提问来源于stack exchange,提问作者Nahuel Valentin Zappani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:15:36