Member-only story

Ethereum, tokens & smart contracts.

Notes on getting started Part 3. Solidity.

Keno Leon
10 min readSep 25, 2017

The next step in this little trek towards making smart contracts and tokens in the Ethereum ecosystem will be to actually start coding contracts and tokens and release them and test them in the wild ( a test net not the real blockchain for now).

Enter Solidity.

In a nutshell, Solidity ( check for the correct docs version !) is the language in which you write contracts, it’s syntax is similar to javascript (importantly it is statically typed and supports libraries and other cool features). So the plan is to write a contract, then compile it and then release/interact with it through web3.js which we briefly covered in the last part of this series. So let’s start with a very very simple contract.

pragma solidity ^0.4.0;contract HelloWorldContract {
function sayHi() constant returns (string){
return 'Hello World';
}
}

While it might look simple, there is a lot going on here, so let’s comment this example:

// You will also need a solidity linter for ATOM ! like linter-solidity// FILE : HelloWorldContract.sol
// Notice the .sol (for solidity) extension.
pragma solidity ^0.4.0;// will not compile with a compiler earlier than version 0.4.0contract HelloWorldContract {
// notice the word contract
function sayHi() constant returns (string){
// As a typed language, this function specifies what it returns via the constant returns (string) bit.
return 'Hello World';
}
}

This contract should respond with “Hellow World” when called (we’ll look into that later) via the sayHi() function.

Compiling :

As mentioned, in order to make contracts work, we first need to compile them and then release or deploy them into the network, the first thing we will need to compile is the solc ( solidity ) node package:

npm install solc

More ways to install: installing-solidity.html

And now in atom we actually do the compiling:

// FILE: compile.js 

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Keno Leon
Keno Leon

No responses yet

Write a response