Ethereum, tokens & smart contracts.
Previous notes in case you are just joining us:
Part 1. Setting up.
Part 2. Web3.js/node.
Part 3. Solidity.
Part 4. Smart Contracts
It feels like we are halfway up the Ethereum mountain, in this part I would like to go a bit deeper into contracts with slightly more advance features we will need later.
Constructors
A constructor (which is common in other languages) simply initializes a contract with some value,operation or set of operations, let’s say we want to store the address of the contract originator ( that’s us), we would do something like this:
FILE: constructorContract.solpragma solidity ^0.4.0;contract constructorContract {address father;function constructorContract() {
father = msg.sender;
}function whosyourfather() constant returns (address) {
return father;
}}
A little extra explanation is in order:
- function constructorContract() is a our constructor function and will only run once in the life of the contract.
- We first define a new…