3

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

3 Answers 3

6

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,

UPDATE 3

Don't use Matic vigil endpoints if deploying upgradeable(Openzeppelin-upgradable plugin) smart contracts using hardhat. Instead, go for Infura endpoints. Sharing my personal experience here.

UPDATE 4

After trying all the RPC endpoints, I will recommend the Alchemy RPC endpoint. Alchemy endpoints are the most trusted and reliable.

4
  • I am getting an issue while deploying using the maticvigil provider url and truffle. Can you please help me?
    – NinjaMAN
    Aug 11, 2021 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, 2021 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, 2021 at 5:56
  • Yes it worked. I was facing similar issue on metamask.
    – Ali Abbas
    Jun 5, 2022 at 15:57
0

A much better solution for this problem is using the truffle dashboard product :>

I completely love it because it removes the need for me to create an account on infura and do all the process of hooking it up on my truffle app.

The process goes like this :

  • Run your truffle dashboard using truffle cli
  • Go to the dashboard on ur browser to the endpoint 24012 which is the default port that is exposed
  • Log in with your metamask
  • Change your metamask network to the network you are trying to deploy your smart contract
  • Add the truffle dashboard network to your network section of truffle config
  • then use truffle deploy with the truffle dashboard network you have just added :>
module.exports = {
  /* ... rest of truffle-config.js ... */

  dashboard: {
    port: 25012,
    host: "localhost"
  }
}

https://trufflesuite.com/blog/introducing-truffle-dashboard/

0

I use truffle to deploy contracts based on the OpenSea sample contracts.

I wanted to migrate from Rinkeby to Mumbai. For this I tried to get a API key for Mumbai on Infura. But Infura wants me to enter a credit card number despite I only wanted to use the free plan.

Thus I migrated to Alchemy. There I got a free plan and an API key for Mumbai. I migrated from Infura to Alchemy following the instruction described here (the second part of the page describes the truffle deployment): https://docs.alchemy.com/alchemy/tutorials/hello-world-smart-contract

But I did not work. The same error as described by metadata in his question.

Then I followed the advices given by metadata in his answer and used the Matic RPC (https://rpc.maticvigil.com/). This worked without any other alterations than using the URL from the Matic RPC instead of the URL of Alchemy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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