Solidity Programing Manual
Solidity Programing Manual
The first line simply tells that the source code is written for Solidity version 0.4.0 or anything
newer that does not break functionality (up to, but not including, version 0.5.0). This is to ensure
that the contract does not suddenly behave differently with a new compiler version. The keyword
pragma is called that way because, in general, pragmas are instructions for the compiler about
how to treat the source code (e.g. pragma once used in c & c++).
Structure of a Contract
Contracts in Solidity are similar to classes in object-oriented languages. Each contract can
contain declarations of State Variables, Functions, Function Modifiers, Events, Struct Types and
Enum Types. Furthermore, contracts can inherit from other contracts.
1.2.1 State Variables
State variables are values which are permanently stored in contract storage.
Events
Events are convenience interfaces with the EVM logging facilities.
contract MyFirstContract {
string private name;
uint private age;
function s
etName(string newName) public {
name = newName;
}
}
Program 3 Basic Banking
pragma solidity ^0.4.0;
interface Regulator {
function checkValue(uint amount) external returns (bool);
function loan() external returns (bool);
}
Bonus Program
pragma solidity ^0.4.0;
interface Regulator {
function checkValue(uint amount) external returns (bool);
function loan() external returns (bool);
}
modifier ownerFunc {
require(owner == msg.sender);
_;
}
function s
etName(string newName) public {
name = newName;
}
contract TestThrows {
function testAssert() public pure {
assert(1 == 2);
}