javascript 错误:PollingBlockTracker-尝试更新最新块时遇到错误:未定义的

7gcisfzg  于 2022-12-02  发布在  Java
关注(0)|答案(2)|浏览(180)

我尝试在多边形区块链上开发DApp。基本上我正在创建NFT,但几次之后我就遇到了这个错误。甚至当我不创建NFT时也会发生这个错误。这是我的代码。

const Web3 = require("web3")
const fs = require("fs")
var HDWalletProvider = require("@truffle/hdwallet-provider");
var provider = new HDWalletProvider(SECRET_PHRASE, "https://rpc-mumbai.maticvigil.com")
const web3 = new Web3(provider)
const constractJSON = JSON.parse(fs.readFileSync(`${process.cwd()}/contracts/Collection.json`))
const abi = constractJSON["abi"]
const byteCode = constractJSON["byteCode"]["object"]



const mintNFT = async (contractAddress,tokenURI,to) => {

    const contract = await new web3.eth.Contract(abi, contractAddress)    

    const result = await contract.methods.claimItem(tokenURI,to).send({from: WALLET_ADDRESS,gasLimit:6000000},)  
}

module.exports = mintNFT

下面是完整的错误。

mint_service_1  | /usr/src/app/node_modules/safe-event-emitter/index.js:74
mint_service_1  |       throw err
mint_service_1  |       ^
mint_service_1  |
mint_service_1  | Error: PollingBlockTracker - encountered an error while attempting to update latest block:
mint_service_1  | undefined
mint_service_1  |     at PollingBlockTracker._performSync (/usr/src/app/node_modules/eth-block-tracker/src/polling.js:51:24)
mint_service_1  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
mint_service_1  | Emitted 'error' event on Web3ProviderEngine instance at:
mint_service_1  |     at safeApply (/usr/src/app/node_modules/safe-event-emitter/index.js:70:5)
mint_service_1  |     at PollingBlockTracker.SafeEventEmitter.emit (/usr/src/app/node_modules/safe-event-emitter/index.js:56:5)
mint_service_1  |     at PollingBlockTracker._performSync (/usr/src/app/node_modules/eth-block-tracker/src/polling.js:53:16)
mint_service_1  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
iyfjxgzm

iyfjxgzm1#

我遇到了同样的问题。您可以查看下面的错误日志

const newErr = new Error(`PollingBlockTracker - encountered an error while attempting to update latest block:\n${err.stack}`)
                       ^
    Error: PollingBlockTracker - encountered an error while attempting to update latest block:
    undefined
        at PollingBlockTracker._performSync (/Users/buuthongtran/Downloads/FlightSurety/node_modules/eth-block-tracker/src/polling.js:51:24)
        at processTicksAndRejections (internal/process/task_queues.js:95:5)
    npm ERR! Test failed.  See above for more details.

我发现我在运行truffle测试之前忘记启动Ganache,所以我试着启动Ganache并输入正确的助记符和端口。之后问题就消失了。

h79rfbju

h79rfbju2#

将此networkCheckTimeout: 10000添加到truffle.config.js

goerli: {
  networkCheckTimeout: 10000,
  provider: () =>
    new HDWalletProvider(PRIVATE_KEY, INFURA_GOERLI_URL),
  network_id: 5,
  gas: 5500000,
  gasPrice: 20000000000,
  confirmations: 2,
  timeoutBlocks: 200,
},

相关问题