Your first Smartcontract in 10 minutes (and you’ve never programmed before)

2018–08–14 | Nick Gorman | The Gulf Blockchain Foundation

For the sake of brevity, definitions used are the absolute bare minimum. If Ethereum was a planet, today’s lesson only looks at the crust.

Ok, we’re going to make our first SmartContract. What is a SmartContract? Its a fancy word for a programme that runs on a distributed network, like a set of instructions. We could send our SmartContract to the Ethereum network, but today, we’re just going to test it locally. What is Ethereum? It is sort of like a great, big Microsoft Windows that runs on thousands of computers all over the world at the same time.

To talk to the network, and get it to do what we want, we can’t give instructions in any human language. We need to speak Ethereum’s language. Ethereum’s language is called Solidity. We will write down our instructions in the Solidity language while working from the Integrated Development Environment (IDE). Think of the IDE as an office with a desk, pen, paper and envelopes. When we want to send our instructions to the Ethereum network, we read our instructions and check for mistakes (this is called compiling) in the IDE and then we put the instructions in an envelope and send it off the network (this is called deploying). To deploy our instructions, we need to chose a delivery company. Our options for a delivery company are:

  • Javascript Virtual Machine (JVM);
  • Web 3 Provider; or
  • Injected Web 3.

Today we’ve chosen the JVM delivery company to deploy our contract. Bizarrely , this company can only deliver the message back into the IDE (in reality it never actually leaves, but that’s a bit red pill for now). It does this so you can see what the final, deployed version will do. Like a test. Here’s a friendly diagram to summarize our plan of action

A friendly caption for a friendly diagram

As you can see the other companies can deliver to different places. We’ll circle back to those in another post.

For now, let’s go to our IDE. Where is it? Right here, silly:

The Integrated Development Environment (IDE)

Looks like somebody left their contract open. Let’s delete their text, and paste our own. Here is what we will paste today:

pragma solidity ^0.4.24;contract hiMark { 
function showMessage () public pure returns (string) {
return 'Oh, Hi Mark'; }


*** Hey you! — come back here later and change the bold characters to improve or break the code. Start with changing ‘Oh, Hi Mark’ to ‘I did naaaat’. Leave the apostrophes in.

If we wrote the code in English, it would read:

  • Use Ethereum language version 0.4.24 or newer.
  • Display some text on the screen. The display action and content is public.
  • The text to display is ‘Oh, hi Mark’.

For now, think of ‘public’ as meaning anyone can open your envelope and read the contents of that specific instruction inside your contract. Like, if you sent aunt Edna your egg-nogg recipe and anyone was allowed to open the envelope and read the 5th ingredient. But nothing else.

Awesome, you’ve just written a SmartContract.

So now what? Remember the steps above?

  1. Write instructions
  2. Compile
  3. Deploy

We’ve done step 1. Now, lets click the button that says “start to compile”. If you have no red warnings, great! Let’s go to step 3.

If you get red warnings, try again from the beginning, or leave a comment below and we’ll help you get through.

To deploy the contract, first click ‘run’ and you’ll get the screen below:

IDE deployment detail (showing deployed contract)

Now we choose our delivery company — the JavaScript VM. Select it. You should see the screen above. Now click ‘deploy’ and the ‘Deployed Contracts’ list is populated.

There it is, in all its glory, your first SmartContract. Now wipe your tears, call your family and tell them you love them and click ‘show message’. Paste the result into the comments below.

If you don’t see the screen below, scroll up, refill coffee and start again.

If you see this:

IDE Deployment detail showing the result of clicking ‘showMessage’

Congratulations, you are the Tim Berners-Lee of the 21st century.

Choose a lambo that matches your yacht and welcome yourself to the world of blockchain.



twitter: @gulfblockchain


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade