0

I am trying to migrate the contract to ROPSTEN network. It fails for the following reason. Please advice.

migrate command

$env:MNEMONIC=' XX XX XX';truffle migrate --reset --network ropsten 

Error

Error: There was a timeout while attempting to connect to the network at undefined.
   Check to see that your provider is valid.
   If you have a slow internet connection, try configuring a longer timeout in your Truffle config. Use the networks[networkName].networkCheckTimeout property to do this.
at Timeout._onTimeout (C:\Users\skmsu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\index.js:57:1)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) 

truffle-config.js

require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider'); 

console.log('ab - from powershell file process.env.MNEMONIC : '+     
 process.env.MNEMONIC);

const infuraProvider = network => providerWithMnemonic( 
process.env.MNEMONIC || '',
`https://${network}.infura.io/${process.env.INFURA_API_KEY}`
);
const providerWithMnemonic = (mnemonic, rpcEndpoint) =>
new HDWalletProvider(mnemonic, rpcEndpoint);

module.exports = {

  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!

  networks: {

development: {
  host: 'localhost',
  port: 8545,
  network_id: '*', // eslint-disable-line camelcase
} , 

mainnet: {
  provider: infuraProvider('mainnet'), 
  gasPrice: 10000000000,  // 10 Gwei
  gas: 4000000,
  network_id: '1'
}, 
ropsten: { 
  provider: infuraProvider('ropsten'), 
  gasPrice: 1000000000,  // 1 Gwei
  gas: 4000000,
  network_id: '3' 
} 
  },

  solc: {
optimizer: {
  enabled: true,
  runs: 200
}
  } 

};
3
  • Add the command you use to migrate please
    – Majd TL
    Sep 11 at 15:48
  • And about infuraProvider(‘ropsten’) , is ‘ropsten’ a placeholder for the url and api key?
    – Majd TL
    Sep 11 at 15:50
  • I have updated the question with migrate command. I use mnemonic seed words in the migrate command. I have also tried the similar for migrating it to ganache development setup. it works fine. but not in ropsten
    – iappmaker
    Sep 11 at 16:03
0
+50

Try using @truffle/hdwallet-provider. truffle-hdwallet-provider deprecated.

Also, verify your Ropsten Project ENDPOINT. i.e: https://ropsten.infura.io/v3/j4hg5g45jhfj8hgfhfghgtg

let me know if this works for you, if not then will find some other ways.

2
  • I have the hdwallet-provider installed perfectly.
    – iappmaker
    Sep 17 at 14:10
  • @iappmaker hdwallet-provider is depricated. try using @truffle/hdwallet-provider Sep 20 at 5:40
0
  1. I assume you have successfully installed @truffle/hdwallet-provider. If you don't, try this
$ npm install @truffle/hdwallet-provider

or see https://github.com/trufflesuite/truffle/blob/develop/packages/hdwallet-provider/README.md#install

  1. put your Infura API KEY to .infura, and mnemonic to .secret. Both are at the same level as truffle-config.js.

  2. change truffle-config.js to something like this

const HDWalletProvider = require('@truffle/hdwallet-provider');

const fs = require('fs');
const infuraKey = fs.readFileSync(".infura").toString().trim();
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)
    },
    ropsten: {
      provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/` + infuraKey),
      network_id: 3,       // Ropsten's id
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      // version: "0.8.0",    // Fetch exact version from solc-bin (default: truffle's version)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: false,
         runs: 200
       },
      }
    }
  },
  db: {
    enabled: false
  }
};
  1. then you can run like this
$ truffle migrate --network ropsten
  1. remember, DO NOT commit the .infura and .secret to GitHub or any repo.

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.