Skip to content

Latest commit

 

History

History
75 lines (42 loc) · 2.01 KB

File metadata and controls

75 lines (42 loc) · 2.01 KB

Deploying first contract

We will now be able to start by opening the solidity editor at https://ethereum.github.io/browser-solidity/.

The code

pragma solidity ^0.4.8;

contract HelloWorld {
    uint256 counter = 0;

    function increase() {
        counter++;
    }

    function decrease() {
        counter--;
    }

    function getCounter() constant returns(uint256) {
        return counter;
    }
}

There is a very simple hello world contract that increases and decreases a counter with functions.

And a function which returns the current counter value which is constant.

Running

Now let's copy the source code.

Make sure our geth private is still running.

We open the wallet and at the bottom left we can see that we are running in the private network.

We click in contracts.

We click on deploy new contract.

We will be in the deploy contract window. Select account, don't give any ehter. and Paste the solidity source code.

Then we want to select the contract to deploy ie hello world.

Then click deploy - and enter the password.

Confirm contract

Now we await for confirmation of the contract. What we need to do to configm contract is to open a new command line window, and start a miner again on the ethereum console.

Done!

Contract is now confirmed, let's stop the miner now.

Play around with contract

If we open the contract we will be able to see how many confirmations it has.

If I go to my contracts, we can play around with my contract by selecting on the "Hello world 36EB" contract.

We can now play around selecting the functions, and choosing to increase/decrease the counter, etc.

We can increase/decrease, which in itself would be a trasaction into our contract, that woudl require a payment.

Let's try it by increasing the counter.

But make sure that you have a miner in the background so that the transactions can be carried forward.

We can now see it's increased, let's increase it again.

And now let's decrease it!