0

I am trying to deploy a simple contract to the Ropsten network using Truffle and Infura. I have set up the Ropsten network in the truffle-confug.js file but it seems truffle always uses the development network.

When I try to migrate the contract using truffle migrate --network ropsten I see the following error:


> simple-eth-server@1.0.0 truffle /home/kuzdogan/Desktop/repos/simple-eth-server
> truffle "migrate" "ropsten"


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > 5777
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Truffle v5.0.25 (core: 5.0.25)
Node v10.16.0

Here is my truffle-config.js

const config = require("./config.js")
const HDWalletProvider = require("truffle-hdwallet-provider");

module.exports = {

  networks: {

    ropsten: {
      provider: function() {
        return new HDWalletProvider(config.mnemonic, "https://ropsten.infura.io/v3/" + config.infuraKey)
      },
      network_id: 3
    }   
  },
}

What I've tried so far:

  • Rename truffle-config.js to truffle.js
  • Adding a development network. Then the URLs and parameters become the same as in truffle-config.js file
  • Renaming ropsten network config to development. In this case the migrate command finishes execution silently, after Everything is up to date, there is nothing to compile.

I somehow have the feeling that the issue is with my Infura config. How can I debug this?

  • What makes you think it is using the development network? You don't even have this network in your Truffle configuration file, and in addition to that, even the error printout tells you that it uses ropsten. – goodvibration Jun 30 at 13:55
  • Because, as I've tried, when I add a network named development in config file, its respective values are printed. Besides 127.0.0.1 and 7545 is the default development config for truffle – kuzdogan Jun 30 at 14:38
1

The problem is with the way I run truffle, nothing with truffle or the code.

I was using truffle as a local npm package. I set up a script in package.json as

"scripts": {
    ": "node_modules/.bin/truffle"
  },

and I was running the binary with

npm run truffle

The script runs normally when compiling:

npm run truffle compile

However, as the network flag is --network this command is not parsed by the npm. This could also be seen in the line above:

> truffle "migrate" "ropsten"

So simply run truffle globally or execute from node_modules/.bin/truffle

0

Seems like I had a problem with using function(), I ended up using fat arrow style:

    ropsten: {
        provider: () => new HDWalletProvider(mnemonic, url, 1),
        network_id: "3"
    }
  • This isn't the problem in my case. I posted my solution above. Thank you for answering. For your case, could it be that you are not returning in your function definition? When there is only one statement, arrow functions return the statement by default – kuzdogan Jul 1 at 18:27

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.