Ethereum beginners guide — Deploy and execute contract within the browser — the very easy way

Cogarius
6 min readOct 11, 2017

--

Hi folks,

Maybe you are wondering what a smart contract is. Maybe you think that you must have a Phd in computer science to be able to deploy one. Maybe you think that you will need specialized 16nm ASIC chip to get some ether to get your hands on this tech.

Well lucky you ! I will show you that a smart contract can be dumb simple to understand deploy and execute and that you will only need a browser to do that :)

First thing first what is a ethereum ? This article will not cover that.

To keep it simple Ethereum is a blockchain that enables smart contract. A smart contract is a piece of code that can be deployed on this peer to peer network that is secure and transparent. We can think about Ethereum like a giant world computer that can not be censored or stopped.

For this network to run smoothly and to avoid Distributed Denial Of Service we must pay this computer but not in dollar in Ether, the underlying crypto currency. Indeed we have to pay to use that giant computer like we have to pay when we want to use cloud services and it is a pay per use. Actually we pay when we store or modify data on this computer not when we read the data as everybody can retrieve the data as long as they have an internet connection.

Now you understand that we will need to get our hands on some ether ! If you want to check the current price of one ether you can go there https://cryptowat.ch/bitfinex/ethusd (today the price is 290$). Don’t worry we will not have to spend one penny because we will use Ether from the test network and this kind of ether is for free as the test network is less secure that the main one.

To “store” ether we will need a wallet that will manage our different accounts.

The fastest way to setup a wallet for our purposes is probably to use the metamask chrome plugin.

When you will launch it be sure to copy the twelve words somewhere as you will need them to recover this wallet.

When the wallet opens take a look at the upper left corner to check on which network the wallet will operate. Select the Ropsten test network

Now let’s copy the address of this account so we can transfer some ether on it. To quickly copy the address click on the three dots next to the account name. A menu will appear then click on “copy address to the clipboard”.

We will use what we call a faucet to get the test Ether for the ropsten network.

Just paste your address in the field and click the button “send me 3 test ether!”

then you should see the message “your request was accepted”

Just way a few seconds and we will see on metamask that your account has been credited with 3 ether !

You can also go to https://ropsten.etherscan.io/ and paste your address on the top right corner to see all the transactions that happened with your account even the pending ones. This website is actually accessing to the whole ethereum test blockchain so that we can see all the accounts, smart contracts and all the transactions that happened from the beginning. Let’s take a look at our account :

We can see that the lastest transaction for our account is indeed the transfer of 3 ether from the faucet account.

Now that we have ether let’s try to create a smart contract. We will use the simple storage contract. This contract only store a decimal number. To store the decimal we have one function called function set() that takes a decimal number and to get the stored data we have a function called function get(). Here is the code of the contract written in solidity one of the language used for ethereum smart contract.

pragma solidity ^0.4.0;

contract SimpleStorage {

uint storedData;

function set(uint x) {
storedData = x;
}

function get() constant returns (uint) {
return storedData;
}

}

If you want to know more about solidity here is the full documentation

We need to compile our contract to send the creation transaction on the network.

Go to the online solidity compiler called Remix

Be sure to have the injected Web3 selected on the run tab under “environment”.Copy paste the contract code on the left window as shown below

Now click on the red create button the metamask plugin will popup a transaction confirmation window.

Once you have clicked approve the transaction to create the contract will be pending.

After a few second we will see the contract ‘s function appear under the create button.

Note: If you have some strange javascript error in Remix try to go through HTTP instead of HTTPS

If we click the detail button on the log window we can see more information about the transaction such as its gas cost or the created contract address.

If you click the blue get button we will read the value of the storage number which is at this moment 0. By the way the blue color is for the constant functions that only read the blockchain data and the red one are for the external functions that will modify the blockchain data.

Let’s enter a number in the text field next to the red button and click on the set button to modify the storage. Metamask again will popup a transaction confirmation window.

After waiting a few seconds the transaction will be mine into a new block and we can check the detail of that transaction.

If you want more details you can go the ropsten.etherscan.io and look for this specific transaction.

Now if we ask for the storage value by clicking the blue get button the value shown is indeed the value that we have send on our set transaction.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

--

--