1

I setup a private blockchain on local using geth.What I did :

  1. create genesis.json
  2. geth init
  3. geth attach
  4. create account , unlock account and mining start
  5. truffle init, write contract, migrations and update truffle.js

module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", } } };

when I try to migrate the contract I am getting the following error :

Could not connect to your Ethereum client. 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.js)

using this command to start a node with geth :

geth --port 3000 --networkid 58342 --nodiscover --datadir="privchain" --maxpeers=0 autodag --rpc --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3" --ipcapi "eth,net,web3"

This is my genesis.json file :

{
  "config": {
    "chainId": 58342,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000033",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x8000000",
  "difficulty": "0x100",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}
  • 2
    According to your truffle configuration, there should be an evm-process (for example, testrpc or ganache) running on your machine and listening on port 8545. – goodvibration May 12 '18 at 7:43
  • 1
    @goodvibration, want to deploy contract on private net , so please suggest if I need to update the truffle.js – Chirag Maliwal May 12 '18 at 11:04
  • 1
    is your geth node correctly opening an RPC interface at http://localhost:8545? and have you specified any --rpccorsdomain arguments whilst starting geth? – TC8 May 12 '18 at 15:20
  • 1
    I used this command to start node with geth : geth --port 3000 --networkid 58342 --nodiscover --datadir="privchain" --maxpeers=0 autodag --rpc --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3" --ipcapi "eth,net,web3" – Chirag Maliwal May 12 '18 at 18:46
  • 1
    I think you should change the port in truffle.js to match your geth port – libertylocked May 14 '18 at 5:13
2

First of all, have a look to the Geth output. It should says something like:

HTTP port opened on localhost:8545

If it said that and you are not able to connect, you can try all of this:

  1. Try to access using your web brownser (I tried with Chrome). If its works you will see your page in white. Sometimes it throws a message such as "invalid host". In that case you should add --rpcvhosts="*" to let any host to connect to your host.

  2. Try to connect using:

    telnet [ipaddress] [port]

Aside from the previously metioned, try to go first for a simply approach. If I were you I would try first:

geth --rpc --rpcport 8545 --rpcaddr "0.0.0.0" --rpccorsdomain "*" --rpcapi "eth,net,web3" --ipcapi "eth,net,web3"
1

If you are setting up your private blockchain on windows, then install the testrpc client using the following command in cmd

npm install -g ethereumjs-testrpc

Then migrate your contract it should work.enter image description here

  • 3
    Better yet, npm install -g ganache-cli. See here. – goodvibration May 12 '18 at 8:25

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.