2

Issue: I fail to migrate(connect) a ethereum private chain on cloud server.

Actual Results

Will:dragon zhuangweiming$ truffle migrate --network development
Using network 'development'.

Running migration: 1_initial_migration.js
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)

Environment

truffle.js

module.exports = {
    networks: {
        development: {
            host: "47.92.53.158",   //this is the IP of ethereum server running on cloud
            port: 8545,             //
            network_id: "15",       // test server.
            from: "0xbe2c0def75c0257f1a9968d2d373febf849d6603", // account created on ethereum 47.92.53.158.
            gas: 4712388,          //default 4712388
            gasPrice: 100000000000  //default 100000000000(100 Shannon)
        }
    }
};

1_initial_migration.js

var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
    deployer.deploy(Migrations);
};

2_deploy_contracts.js

var Dragon = artifacts.require("./Dragon.sol");
module.exports = function(deployer) {
  deployer.deploy(Dragon);
};

I tried geth command as below:

geth --networkid 15 --datadir data --rpc --rpcapi 'web3,eth,net' --rpccorsdomain '*' --rpcaddr 0.0.0.0 --rpcport 8545 --port 30303 console
2
  • Is the port 8545 open in your server? Also be aware if you expose that port to the internet then anyone else will be able to interact with your server. I'd advice to use a ssh tunnel or a password protected proxy with nginx or similar.
    – Ismael
    Feb 1, 2018 at 3:57
  • Yes, correct. I need to open 8545 on cloud, I also open 30303, but not sure if it is necessary. Thank you very much! Could you kindly paste it into answer?
    – Will_Z
    Feb 1, 2018 at 6:14

2 Answers 2

2

In my case, it worked after modifying truffle.js.

The exact steps were:

While starting the private network:

geth --datadir=mychaindata\ --nodiscover --rpc

it showed port opened at 8545 (I didn't use --rpccorsdomain there because truffle migrate doesn't work then)

In truffle.js changed port to 8545 and after that add a gas value:

port: 8545
gas: 3000000 // added because on truffle migrate, it showed exceed gas value error

I unlocked the accounts and started miner in a separate geth attach then tried truffle migrate, Migration completed successfully.

Also, after running npm run dev it showed failing back to port 9545 error.

I modified app.js by changing the port to 8545. Refreshing the page showed cross-origin error, so I stopped the network and restarted like:

geth --datadir=mychaindata\ --nodiscover --rpc --rpccorsdomain --unlock 0 --mine 1

After accepting the password, network started and everything worked well!

1
  • Similar error for me just update the port in the truffle-config.js Apr 30, 2021 at 21:19
0

I am not an expert in truffle/geth,... but if you deploy a contract on the network you have to pay gas for it. So perhaps you need to unlock your account somehow.

If this should be the problem you can try unlocking Account

0xbe2c0def75c0257f1a9968d2d373febf849d6603

as described here.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.