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

Truffle部署报错PollingBlockTracker:Polygon Amoy与Sepolia网络均失败

部署智能合约到测试网触发PollingBlockTracker错误的解决办法

问题背景

部署智能合约到Polygon Amoy和Sepolia测试网时,均出现相同的PollingBlockTracker错误。已确认Ganache、MetaMask钱包与.secret文件使用同一助记词,且MetaMask网络配置与truffle-config.js一致。

报错信息

Compiling your contracts...
===========================
⠇ Fetching solc version list from solc-bin. Attempt #1
/home/ahmed/PycharmProjects/payment-dapp/node_modules/eth-block-tracker/src/polling.js:51
        const newErr = new Error(`PollingBlockTracker - encountered an error while attempting to update latest block:
${err.stack}`)
                       ^
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
undefined
    at PollingBlockTracker._performSync (/home/ahmed/PycharmProjects/payment-dapp/node_modules/eth-block-tracker/src/polling.js:51:24)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

当前truffle-config.js配置

const HDWalletProvider = require("@truffle/hdwallet-provider");
const fs = require("fs");
const mnemonic = fs.readFileSync(".secret").toString().trim();
require('dotenv').config()

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 7545,
      network_id: "*",
    },
    sepolia: {
      provider: () =>
        new HDWalletProvider(
          mnemonic,
          `https://sepolia.infura.io/v3/`
        ),
      network_id: 11155111,
      confirmations: 2,
      gas: 5500000,
      gasPrice: 45000000,
      networkCheckTimeout: 10000000,
      timeoutBlocks: 200,
      skipDryRun: true,
      chainId: 11155111,
    },
  },
  contracts_directory: "./contracts",
  contracts_build_directory: "./abis",
  compilers: {
    solc: {
      version: "^0.8.19",
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },

  db: {
    enabled: false,
  },
};

修复步骤

  • 补全节点API密钥:当前Sepolia的Infura URL末尾缺失API密钥,需补充为https://sepolia.infura.io/v3/你的项目ID;Polygon Amoy同理,比如使用Infura节点的话格式为https://polygon-amoy.infura.io/v3/你的项目ID,或替换为Alchemy等其他节点服务的完整URL。
  • 验证节点连接:直接访问节点URL,确认返回合法的JSON-RPC响应,确保节点服务正常运行。
  • 调整超时参数:若网络延迟高,适当调大networkCheckTimeout值,比如改为15000000,避免同步超时。
  • 检查账户余额:确认助记词对应的账户在目标测试网有足够测试币(Sepolia ETH、Amoy MATIC),无测试币无法支付Gas费用。
  • 更新依赖包:执行npm update @truffle/hdwallet-provider eth-block-tracker,更新到最新版本解决兼容性问题。

内容的提问来源于stack exchange,提问作者Ahmed B

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 09:50:00