2

So I've followed the greeter contract tutorial from here to deploy a contract to my private cloud. It works fine and all, but it is rather difficult that I need to create a string from my contract and then deploy that. It would be easier if I could create a contract.sol file and compile that.

So I put the greeter code into a file:

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 greet() constant returns(string) {
        return greeting;
    }
}

and ran the following command:

solc --optimize --bin contract.sol

This creates two new files:

greeter.bin
mortal.bin

But from here I'm kinda lost. Does anybody know how I can deploy this greeter contract using geth and these two bin files? All tips are welcome!

pringi
  • 133
  • 6
kramer65
  • 655
  • 1
  • 6
  • 11

2 Answers2

1

The geth Javascript console is more adapted to interactive use, when compiling directly with solc, RPC is usually a better choice. To deploy contracts see:

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction

You can write a simple bash script to compose the json parameter and pass the right data in.

Matthieu
  • 246
  • 1
  • 2
  • Thanks for the link. I had a read through it. I now understand how I can send ether using the RPC interface, but I'm unfamiliar with the command to deploy a contract. Would you possibly have an example of how to do that using the RPC interface? – kramer65 Aug 26 '16 at 08:58
  • May be this can help : https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction – Aniket Sep 14 '16 at 07:04
0

Try the web3 CLI tool, you can just run:

web3 contract deploy greeter.bin

That will deploy and return the contract address.

Can also build with: web3 contract build greeter.sol

Travis Reeder
  • 471
  • 5
  • 8