2

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.

3

You can try the name registrar contract that is used to associate your contract's address with a name. In case of a private testnet, you will need to deploy the registrar code on your network. In order to do that, you will first have to compile the code from their git repo, and deploy them on your network just as you would do for any other contract.

For more information on Registrar:What is the Global Registrar?

Another approach to interacting with a contract is using the NatSpec Protocol. For further information on that, here is the link: NatSpec Github wiki.

  • Please show me how to deploy registrar. I'm working on go-ethereum console. And it's too difficult to find "registrar" – Ajk Thu Jul 27 '16 at 9:41
  • I've edited my answer to include the answer to your query – rupshabagchi Jul 27 '16 at 9:58
  • I tried remove lines and break content of "GlobalRegistrar.sol". Then i continue to compile by "web3.eth.compile.solidity" but it has some strange erros. Please show me how can load "GlobalRegistrar.sol" from console. Thanks – Ajk Thu Jul 27 '16 at 10:28

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.