7

When I run truffle develop it starts a testnet listening at localhost:9545. Is there a way to change the port this testnet is running on? EDIT: I'm not looking for a way to configure which network truffle connects to. I'm trying to run truffle's development testnet on another port than 9545, which it takes by default. The reason is that it would make it easier to run the code on TestRPC as well.

  • config file..... – Slim Shady Nov 19 '17 at 11:39
  • Where do I find that? It's not the truffle.js in my project I think, that's for configuring the app itself? – Alex Nov 19 '17 at 12:29
  • truffle.js or truffle-config.js in root folder – Slim Shady Nov 19 '17 at 12:30
1

You could also add another network to your truffle.js file. Something like this:

networks: {
  development: {
    host: "localhost",
    port: 9545,
    network_id: "*" // match any network
  },
  mynetwork: {
    host: "localhost",
    port: 8545,
    network_id: "*" // match any network
  },
}

No you can you can run truffle migrate --network mynetwork. Like this the contracts will be migrted to testrpc.

  • This comes closest to solving the issue so I'll mark this as the answer – Alex Nov 26 '17 at 18:56
  • When I do this truffle develop still starts with http://localhost:9545/. Even when changing all the ports to something other than 9545. This link indicates that 9545 cannot be changed: truffleframework.com/docs/advanced/… – Stan James Dec 18 '17 at 22:00
1

I had the same question. If anyone else does, here is what worked for me: You can use ganache-cli to create a test blockchain and then truffle migrate to connect to it, the same way truffle develop does it under the hood.

Create custom test blockchain:

$ npm install -g ganache-cli
$ ganache -p 9546 # custom port 9546

And then in truffle.js add this custom network configuration

module.exports = {
  networks: {
    "customNetwork": {
       network_id: 1,
       host: "127.0.0.1",
       port: 9546 // the port that Ganache-cli exposes
     }
  }
};

Then finally connect truffle to the network and deploy the contracts with

$ truffle console --network customNetwork
truffle(customNetwork)> migrate --reset

I hope this helps

0

I guess you would have found the answer from the comments, the config file is the file named truffle.js which is present in the root directory of the project.

You can change the port and other things from truffle.js. Specifically, port can be changed by:

module.exports = {
  networks: {
    development : {
      host : "localhost",
      from: <Some_address>,
      port: 9545,
      gasPrice: 12,
      gas: 4700000
    }
  }
};
  • Just edited my question to make it more clear what I'm trying to do. I'm trying to configure truffle's development testnet, not the application I'm building – Alex Nov 20 '17 at 6:52
0

As per the truffle's documentation, truffle develop doesn't read the port from truffle.js file.

This will spawn a development blockchain locally on port 9545, regardless of what your truffle.js configuration file calls for.

0

I had the same problem :) Because I wanted to see the logs, I needed to use my local network and the result of running following command: "truffle develop", will start tests on their default develop environment. So that what happened to you is the expected behavior. :)

This is how you could run it on your desired network:

This is the content of truffle.js file:

    module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*', // Match any network id
      gasPrice: 20000000000 // Same value as `truffle develop`
    }
  }
}

After this, run your tests with this command: truffle test (before that you need to start node, for example with this: ganache-cli -> to install it use this command: npm i -g ganache-cli)

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.