I created a private network using go-ethereum with 2 clien which are VMs(ubuntu 14.04).
On VM1, I created a contract:
N1greeterSource ='contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function changeMessage(string myMsg) returns (string){ greeting = myMsg; return myMsg; } function greet() returns (string) { return greeting; } }'
N1greeterCompiled = web3.eth.compile.solidity(N1greeterSource);
_greeting = "Hello world !";
N1greeterContract = web3.eth.contract(N1greeterCompiled.greeter.info.abiDefinition);
N1greeter = N1greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: N1greeterCompiled.greeter.code, gas: 310000}, function(e, contract){
if(!e) {
if(!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
else{
console.log("Error:>>>>>>>>>>>>>");
console.log(e);
}
})
On VM2, I see contract by:
N1greeter = eth.contract([{ constant: false, inputs: [], name: "kill", outputs: [], type: "function" }, { constant: false, inputs: [{ name: "myMsg", type: "string" }], name: "changeMessage", outputs: [{ name: "", type: "string" }], type: "function" }, { constant: false, inputs: [], name: "greet", outputs: [{ name: "", type: "string" }], type: "function" }, { inputs: [{ name: "_greeting", type: "string" }], type: "constructor" }] ).at("0x526e636021fbfef1584097690798145ff32be21a");
Everything is OK.
But, I don't know how to VM2 can automaticlly find the contract? (find address and abi in VM1 to add this code: N1greeter = eth.contract(abi).at(address))
Thanks.