Smack dab right in the middle of the page we can see our space for our code. In the upper left of the screen we can see a few different file options available: “Create New File”, “Add Local File”, “Publish All Open Files to an Anonymous Github Gist”, “Copy All Files to Another Instance”, and lastly “Connect to Localhost”. We can also see a list of current contracts under development.

On the upper right side of our screen we have several tabs to select from. Our “Compile” tab allows for us to compile our contract once complete (set to Auto compile by default). If we click on “details” we get a list of several contract details ranging from metadata, to bytecode, to ABI, and even our contract’s Web3 deployment code.

The “Settings”, “Debugger”, “Analysis”, and “Support” tabs all have their use case and are worth familiarizing yourself with. In the interest of time we’re going to be using the “Run” tab for the rest of this tutorial. If we click on the “Run” tab we can see a few different contract settings.

Environment: There are 3 type of environments Remix can be plugged to. Both the Web3 Provider and Injected Web3 environments require external tools like MetaMask or Mist. JavaScript VM is what we’ll stick to, as it will allow for execution to take place in our browser, in addition to our deployment in Mist.

Account: Remix provides 5 different accounts with 100 Ether preloaded! These can be used during contract development if desired.

Gas limit: Set a limit forthe amount of gas (fee) attached to the contract.

Gas Price: Set a required amount of gas for the contract.

Value: Deploy the contract with X amount of ether attached.

Finally…Hands On Solidity!

For those of you familiar with Javascript I’m sure you’ll take notice to the overlaps with Solidity. Much like JS, Solidity is a contract-oriented, high-level language that is designed to target the Ethereum Virtual Machine (EVM). The code is statically typed, supports inheritance, libraries and complex user-defined types among other features.

In our “Hello World!” contract we’re going to create a state variable called counter and assign it a starting value of 5. Then we’re going to create a function that increases our state variable by 1, a function that decreases the variable by 1, a function that returns our counter , and lastly a function that will destroy the contract.

The first bit of code that we’ll type into Remix is the source code version. At the time of writing this Solidity 0.4.16 is the latest version that is recognized by Mist. We’re going to call this version by typing at the top of our contract:

pragma solidity ^0.4.16;

The keyword pragma is called that way because generally pragmas are instructions for the compiler about how to treat the source code.

More info on Solidity can be found here in the docs: https://solidity.readthedocs.io/en/develop/index.html

Functions & States

Looking at the bare bones of a smart contract we can see that contracts are merely collections of code (its functions) and data (its states) that correspond to a specific contract address on the blockchain.

For example, the line uint256 counter; sets the variable counter of type uint256 (unsigned integer of 256 bits). It can now be thought of as a single slot in a database that can be pulled by calling the function of the code that manages the database. We can even set a value for the variable counter while also setting the type as uint256.

uint256 counter = 5;

State variables are typically outside of functions, making them global variables, and usually are the first few lines in our contract. We’ve now managed to set our variable counter as an uint256 and a value of 5. If we want to call a function to increase the value of counter by 1, we’re going to create a function (we’ll call it “add”) and tell it to add 1 to counter .

function add() public {

counter++;

}

After calling the function “add()”, counter will have a value of 6.

Building Out The Contract

Lets create our “Hello World!” contract by first creating a contract called such:

pragma solidity ^0.4.16; contract HelloWorld {





}

We can now include that counter state variable that we talked about early. Remember, we’re going to assigning this state variable as an unsigned integer of 256 bits (unsigned meaning that this type can only be positive integers, not positive and negative. 256 bits in size is a design of the Ethereum Virtual Machine). Oh yeah, also set it to a value of 5.

pragma solidity ^0.4.16; contract HelloWorld { uint256 counter = 5;



}

Go ahead and see if you can create 2 functions below this state variable assignment. We need 1). a function that increases counter by 1 and 2). a function that decreases the counter by 1.

pragma solidity ^0.4.16; contract HelloWorld {



uint256 counter = 5; //state variable we assigned earlier function add() public { //increases counter by 1

counter++;

}



function subtract() public { //decreases counter by 1

counter--;

}





}

You’ll see from the code above that we assigned both functions the modifier public . Since Solidity knows two kinds of function calls (internal ones that do not create an actual EVM call — also called a “message call” — and external ones that do), there are four types of visibilities for functions and state variables. Functions can be specified as being external , public , internal or private , the default is public . Aside from the fact that Remix will throw a warning message stating that no visibility is specified and it’s defaulting to public , typing out the function visibility is a good habit to get into. It will allow us to better understand the contract settings when evaluating our code.

We’re getting close, but not quite there. Our state variable can change depending on the function we call, but we need a function that will output the value of counter . Try creating a function called “getCounter()” that will return counter . This will be a read only action, so we need to tell our function that we’ll be returning a constant. Additionally, when returning a state variable we must tell our function the type that is being returned, in this case we’re returning an uint256 as discussed earlier.

pragma solidity ^0.4.16; contract HelloWorld {



uint256 counter = 5; //state variable we assigned earlier function add() public { //increases counter by 1

counter++;

}



function subtract() public { //decreases counter by 1

counter--;

} function getCounter() public constant returns (uint256) {

return counter;

}

}

While calling a functions on the Ethereum network will require a small amount of gas to be spent, no gas is required when returning a constant function.

Awesome! So now we have a contract that allows us to change the value of our global variable counter . We can also increase it by 1, decrease it by 1, and return the value of our counter whenever we want. Let’s give it a whirl…

Let’s Test This Thang

So your code should be in Remix and “Auto compile” should be checked by default under the “Compile” tab. Make your way over to the “Run” tab. Default settings will have the environment set to JavaScript VM, an account will be selected, gas limit will be 3000000, and your gas price & value will be 0. Click on “Create” under your “Run” tab. You should now see your contract created just like below.

Notice the amount of ether on our account ticked down slightly from 100 after creating the contract.

Right off the bat you can see the 3 functions that we had created — “add”, “substract”, and “getCounter”. You can also see that our state variable has a value assigned to it of 5. Now, click “add” to increase our counter by 1. Then go ahead and click “getCounter” to call our newly modified counter . You should see the value has been updated to 6. Try it again for “subtract”.

WOOHOO! Give yourself a pat on the back. You just done did it. Contract created!

Deploying Contracts in Mist

Now that we’ve tested and confirmed our code in Remix, let’s start up Mist (make sure it’s connected to the Private Network) and deploy it on our private network. Navigate to the “Contracts” tab of the Ethereum Wallet in Mist. Then select “Deploy New Contract” and paste our code from Remix into the source code box.

Before we can proceed any further, we need to have ether in our wallet. We can mine for ether on our private network by running the miner. We’ll do this through the Geth JavaScript console.

Open up ANOTHER command prompt window pointing to your private network folder (C:/users/name/desktop/private network) and type geth attach . Hit enter. You will see a Geth JavaScript console generated and you can now enter commands into Geth directly. Let’s begin mining for some ether by typing miner.start(); . You will see that the console returns “null” and mining has begun! Take a look at your wallet on Mist, you’ll see increments of 5 ether continuously added to your wallet. You can stop the miner anytime by typing miner.stop(); in console…or you can continue to mine fake ether…whatever makes you happy!

Learn more about JS console commands here: https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console