8

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.

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

7 Answers 7

3

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
  },
}

Now you can run truffle migrate --network mynetwork. Like this, the contracts will be migrated to testrpc.

2
  • This comes closest to solving the issue so I'll mark this as the answer
    – Alex
    Commented Nov 26, 2017 at 18:56
  • 2
    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
    Commented Dec 18, 2017 at 22:00
5

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

3

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 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
    }
  }
};
1
  • 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
    Commented Nov 20, 2017 at 6:52
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)

0

Piggybacking on @Pani response here. But instead of using the Gnache CLI, you can also use the Gnache GUI.

Step 1 Download the Gnache GUI here Gnache interface

Step 2

Follow the instructions here, this will kickstart the testnet EVM, which will allow you to migrate your code to the EVM. I thought truffle develope already does that, but it doesn't seem to do it.

0

use

     develop: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 7545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },

the name is develop as the office website description You can configure truffle develop to use any of the available ganache-core options and configurable network settings.

For example:

module.exports = {
  /* ... rest of config */

  networks: {
    /* ... other networks */

    develop: {
      port: 8545,
      network_id: 20,
      accounts: 5,
      defaultEtherBalance: 500,
      blockTime: 3
    }
  }
};

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.