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!

4
  • @niksmac - The question you're linking to is not a duplicate. That deals with deploying from within the geth console by using the contract as a string. What I want to do is deploy a contract from a solidity source file.
    – kramer65
    Commented Aug 17, 2016 at 16:55
  • I guess the only way to deploy smart contracts is to send bytecode to the blockchain through a transaction. You cannot deploy the source file. The code needs to be compiled and deterministic since it's being run in the EVM.
    – galahad
    Commented Aug 17, 2016 at 19:32
  • @kramer65 then this might help ethereum.stackexchange.com/q/2609/259
    – niksmac
    Commented Aug 18, 2016 at 0:40

2 Answers 2

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.

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
    Commented Aug 26, 2016 at 8:58
  • May be this can help : github.com/ethereum/wiki/wiki/…
    – Aniket
    Commented Sep 14, 2016 at 7: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

Your Answer

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

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