Ethereum, tokens & smart contracts.

Notes on getting started Part 4. Smart Contracts

Keno Leon
10 min readOct 1, 2017

--

Previous notes in case you are just joining us:
Part 1. Setting up.
Part 2. Web3.js/node.
Part 3. Solidity.

Our hello world contract from the previous notes while awesome, is not particularly smart, we now need to start adding complexity and features in order to really create a smart contract, let’s start with with giving it some memory in the form of basic storage.

Basic Storage:

FILE: basicStorage.sol/* Stolen from the docs */pragma solidity ^0.4.0;contract basicStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint) {
return storedData;
}
}

There is not much happening here, a variable declaration and 2 contract methods in the form of a getter and a setter which will allow us to save and modify storedData. For comparisons sake this is what a similar javascript class would look like:

// JAVASCRIPT ES6
// Source : dVvoWr
class basicStorage {
constructor(Data) {
this.storedData = Data;
}

set(x) {
this.storedData = x…

--

--

Keno Leon
Keno Leon

No responses yet