0

I'm trying to use Polygon test network with truffle and I followed this document and youtube video to configure Polygon network for truffle. But when I'm trying to execute truffle deploy --network matic then it failed with below errors.

Error logs

Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: Unknown Error: {"statusCode":404,"error":"Not Found"}
    at Request._callback (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/@trufflesuite/web3-provider-engine/subproviders/rpc.js:57:23)
    at Request.self.callback (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:315:20)
    at IncomingMessage.<anonymous> (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:421:28)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
    at PollingBlockTracker._performSync (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/eth-block-tracker/src/polling.js:51:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
UnhandledRejections detected
Promise {
  <rejected> {
    code: -32603,
    message: 'Unknown Error: {"statusCode":404,"error":"Not Found"}',
    data: { originalError: {} },
    stack: 'Error: Unknown Error: {"statusCode":404,"error":"Not Found"}\n' +
      '    at Request._callback (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/@trufflesuite/web3-provider-engine/subproviders/rpc.js:57:23)\n' +
      '    at Request.self.callback (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:185:22)\n' +
      '    at Request.emit (events.js:315:20)\n' +
      '    at Request.<anonymous> (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:1154:10)\n' +
      '    at Request.emit (events.js:315:20)\n' +
      '    at IncomingMessage.<anonymous> (/home/alpha/GoWorkspace/src/github.com/metadata/solidity_e2e/node_modules/request/request.js:1076:12)\n' +
      '    at Object.onceWrapper (events.js:421:28)\n' +
      '    at IncomingMessage.emit (events.js:327:22)\n' +
      '    at endReadableNT (internal/streams/readable.js:1327:12)\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:80:21)'
  }
}

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.matic.today`),
      //host: 'https://rpc-mumbai.matic.today',
      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.5",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

  // Truffle DB is currently disabled by default; to enable it, change enabled: false to enabled: true
  //
  // Note: if you migrated your contracts prior to enabling this field in your Truffle project and want
  // those previously migrated contracts available in the .db directory, you will need to run the following:
  // $ truffle migrate --reset --compile-all

  db: {
    enabled: false
  }
};

Setup Information

  1. WSL2 Ubuntu 18.04
  2. Node version: v14.15.4
  3. npm version: 6.14.10
  4. Solidity compiler: 0.8.5
  5. truffle version: v5.3.11 (core: 5.3.11)
  6. Web3.js: v1.3.6
1

After updating the RPC endpoint to https://rpc-mumbai.maticvigil.com from https://rpc-mumbai.matic.today in truffle-config.js it started working fine. It seems that Polygon team updated the RPC endpoint but hasn't updated it in the document.

UPDATE

It's better to create an account on Matic-vigil and then generate the RPC endpoints for polygon-test and finally use this endpoint with Metamask and other services like truffle and hardhat.

UPDATE-2

  1. Create an account on https://rpc.maticvigil.com/.
  2. create an app let's say truffle test which will generate four endpoints.
  3. Two for Mainnet(https and WebSocket) and two for testnet. Use testnet https endpoint which looks like https://rpc-mumbai.maticvigil.com/v1/ID where ID is unique for every user.
  4. Now add this endpoint to truffle-config.js. Below is the snippet.
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/v1/ID`),
    network_id: 80001,
    confirmations: 2,
    timeoutBlocks: 200,
    skipDryRun: true
  },
},

  1. If you are using hardhat then follow the below snippet.
defaultNetwork: "polygon_test",
  networks: {
    hardhat: {
    },
    polygon_test: {
      url: `https://rpc-mumbai.maticvigil.com/v1/ID`,
      chainId: 80001,
3
  • I am getting an issue while deploying using the maticvigil provider url and truffle. Can you please help me?
    – NinjaMAN
    Aug 11 at 5:13
  • @NinjaMAN I have added the steps in my answer. please try it out. Also please share the error logs.
    – metadata
    Aug 12 at 5:17
  • Its better to raise the concern separately which I did in ethereum.stackexchange.com/questions/106682/…. With maticvigil provider its like same issue.
    – NinjaMAN
    Aug 12 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.