Using Ethereum With Remix IDE

Follow

Remix is a powerful, open source tool that helps you write Solidity contracts straight from the browser. Written in JavaScript, Remix supports both usage in the browser, and locally.

Remix also supports testing, debugging and deploying of smart contracts.

The Remix project with all its features is available at remix.ethereum.org. The IDE tool is available at this GitHub repository.

 

Getting Started:

 You can then run and monitor your contracts right from your Mist browser, the same place you can manage your Ethereum wallet account(s).  Once you've launched Mist and connected to your node you can click on the <Contracts> button on the Mist application UI.

 

A Sample __Hello World__ greeter smart contract

Your first citizen: the Greeter

The Greeter is an intelligent digital entity that lives on the blockchain and is able to have conversations with anyone who interacts with it, based on its input.

Here is its code:

contract Mortal {
    /* Define variable owner of the type address */
    address owner;

    /* This function is executed at initialization and sets the owner of the contract */
    function Mortal() { owner = msg.sender; }

    /* Function to recover the funds on the contract */
    function kill() { if (msg.sender == owner) selfdestruct(owner); }
}

contract Greeter is Mortal {
    /* Define variable greeting of the type string */
    string greeting;

    /* This runs when the contract is executed */
    function Greeter(string _greeting) public {
        greeting = _greeting;
    }

    /* Main function */
    function greet() constant returns (string) {
        return greeting;
    }
}

You'll notice that there are two different contracts in this code: "mortal" and "greeter". This is because Solidity (the high level contract language we are using) has inheritance, meaning that one contract can inherit characteristics of another. This is very useful to simplify coding as common traits of contracts don't need to be rewritten every time, and all contracts can be written in smaller, more readable chunks. So by just declaring that greeter is mortal you inherited all characteristics from the "mortal" contract and kept the greeter code simple and easy to read.

The inherited characteristic "mortal" simply means that the greeter contract can be killed by its owner, to clean up the blockchain and recover funds locked into it when the contract is no longer needed. Contracts in ethereum are, by default, immortal and have no owner, meaning that once deployed the author has no special privileges anymore. Consider this before deploying.

USING REMIX

As of 2018, the most convenient way to develop contracts is using Remix, an online IDE.

To access the compiled code, ensure that the dropdown menu on the right pane has greeter selected. Then click on the Details button directly to the right of the dropdown. In the popup, scroll down and copy all the code in the WEB3DEPLOY textbox.

Create a temporary text file on your computer and paste that code. Make sure to change the first line to look like the following:

var _greeting = "Hello World!"

Now you can paste the resulting text on your geth window, or import the file with loadScript("yourFilename.js"). Wait up to thirty seconds and you'll see a message like this:

Contract mined! address: 0xdaa24d02bad7e9d6a80106db164bad9399a0423e

You may have to "unlock" the account that is sending the transaction using the password you picked in the beginning because you need to pay for the gas costs to deploying your contract: 

Within less than a minute, you should have a log with the contract address, this means you've successfully deployed your contract. You can verify the deployed code (which will be compiled) by using this command:

eth.getCode(greeter.address)

If it returns anything other than "0x" then congratulations! Your little Greeter is live! If the contract is created again (by performing another eth.sendTransaction), it will be published to a new address.

Run the Greeter

In order to call your bot, just type the following command in your terminal:

greeter.greet();

Since this call changes nothing on the blockchain, it returns instantly and without any gas cost. You should see it return your greeting:

'Hello World!'

 

Resources:

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.