4

I'm using truffle (which uses pudding) to deploy contracts to my testrpc.

No I'm running a geth instance locally with:

geth --mine -rpccorsdomain "*" --ipcapi "admin,eth,miner" --rpcapi "eth,web3" --networkid 1100 --maxpeers 5 --minerthreads 1 --unlock "0xXXXXXXXXetc.." console

Now when I try to deploy my contracts, I get:

Invalid JSON RPC response: "Error: connect ECONNREFUSED 127.0.0.1:8545 at..."

What am I missing here? How does truffle/pudding identify itself to the node, when it deploys? (i.e. truffle deploy) I can't see anything to configure this.

2

Turned out that the default port is not 8545, and had to add these options:

--rpc --rpcport 8545

  • Actually, the default port is 8545, but you need to use the --rpc flag to enable RPC connections – Tjaden Hess Sep 1 '16 at 22:56
1

Contract compilation is described in detail here; an example may look like:

./geth --datadir ~/eth/ --loglevel 6 --logtostderr=true --rpc --rpcport 8100 --rpccorsdomain '*' --mine console  2>> ~/eth/eth.log
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_compileSolidity","params":["contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"],"id":1}' http://127.0.0.1:8100

(make sure you are connecting to the right ports).

Contract deployment is shown here:

source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
// compile with solc
contract = eth.compile.solidity(source).test
// create contract object
var MyContract = eth.contract(contract.info.abiDefinition)
// extracts info from contract, save the json serialisation in the given file, 
contenthash = admin.saveInfo(contract.info, "~/dapps/shared/contracts/test/info.json")
// send off the contract to the blockchain
MyContract.new({from: primaryAccount, data: contract.code}, function(error, contract){
  if(!error && contract.address) {
    // calculates the content hash and registers it with the code hash in `HashReg`
    // it uses address to send the transaction. 
    // returns the content hash that we use to register a url
    admin.register(primaryAccount, contract.address, contenthash)
    // here you deploy ~/dapps/shared/contracts/test/info.json to a url
    admin.registerUrl(primaryAccount, hash, url)
  }
});
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Waqar Lim Jul 12 '16 at 15:41
  • Done, edited the answer. – Sebi Jul 12 '16 at 16:24
  • The question is more about how truffle identifies itself to a node, i.e. which account is it using to deploy (when doing truffle deploy) – BlockChange Jul 25 '16 at 8:43
1

First of all,you need to add a rpc port in your geth as : geth --rpc --rpcport "portnumber".
Then in your truffle project folder there will a file named truffle.js.You need to update the rpc section as section

rpc: {
   host: "localhost",
   port: portnumber
 }

Thus it will be connected to tehy node running locally on your system.Now you just need to run the command truffle deploy and your contracts will be deployed on your private blockchain. Error is appearing because of the default value set in truffle.js file which is trying to connect a local node running on the port 8545. I hope it will resolve your issue.

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.