Skip to content

Instantly share code, notes, and snippets.

@jasonyunjoonpark
jasonyunjoonpark / StoreNumber.sol
Created December 30, 2017 23:50
Store a number and returns a number.
pragma solidity ^0.4.19;
contract storeFavoriteNumber{
mapping (address => uint) favoriteNumber;
function setMyNumber(uint _myNumber) public {
favoriteNumber[msg.sender] = _myNumber;
}
function returnNumber() public view returns (uint) {
@jasonyunjoonpark
jasonyunjoonpark / HelloWorld.sol
Last active January 1, 2018 15:39
Hello World contract.
pragma solidity ^0.4.19;
contract helloWorld{
string word = "Hello World!";
function getWord() public view returns(string){
return word;
}
function setWord(string newWord) public returns(string){
@jasonyunjoonpark
jasonyunjoonpark / Modifier.sol
Last active January 2, 2018 01:45
Only owner of the smart contract can modify message of this contract
pragma solidity ^0.4.19;
contract helloWorld{
string word = "Hello World!";
address owner;
function helloWorld() public {
owner = msg.sender;
}
@jasonyunjoonpark
jasonyunjoonpark / PayableContract.sol
Last active January 2, 2018 01:44
Contract that can receive ether and return the balance.
pragma solidity ^0.4.19;
contract payableContract {
function payableContract() public {
}
function receive() public payable {
@jasonyunjoonpark
jasonyunjoonpark / CallerContract.sol
Last active January 2, 2018 01:44
Using a contract to call another contract that exists in the same file.
pragma solidity ^0.4.19;
contract callerContract {
calledContract toBeCalled = new calledContract();
function receive() public constant returns (uint) {
return toBeCalled.getNumber();
}
}
@jasonyunjoonpark
jasonyunjoonpark / Inheritance.sol
Last active January 2, 2018 01:43
Two contracts inheriting a function from another contract.
pragma solidity ^0.4.19;
contract mortal {
address public owner;
function mortal() {
owner = msg.sender;
}
modifier onlyOwner {
@jasonyunjoonpark
jasonyunjoonpark / Calculator.sol
Created January 1, 2018 18:49
Calculator contract that calls another contract to function.
pragma solidity ^0.4.19;
contract Calculator {
Math math = new Math();
function TwoPlusFour() public view returns (int) {
return math.add(2,4);
}
function TwoTimesFour() public view returns (int) {
return math.multiply(2,4);
@jasonyunjoonpark
jasonyunjoonpark / Paycheck.sol
Last active January 3, 2018 04:20
Smart contract that allows 4 employees to withdraw an equal amount of ether deposited to the contract by the deployer.
pragma solidity ^0.4.18;
contract Paycheck {
address[] Employees = [0xd2dE66A09F48A96b8cd429951ca70F79715beBCc, 0x80bFb3c5C9386e687936868A79f2e626F38a4AC2, randomaddress, randomaddress];
mapping (address => uint) WithdrawnAmount;
function Paycheck() public payable {
}
@jasonyunjoonpark
jasonyunjoonpark / SavingsAccount.sol
Last active January 4, 2018 00:24
Smart contract that acts as a savings account for the deployer of the contract. Only the deployer can withdraw from this contract.
pragma solidity ^0.4.18;
contract SavingsAccount {
address owner;
event UpdateStatus(string msg);
event UserStatus(string msg, address user, uint amount);
function SavingsAccount() public {
owner = msg.sender;
}
@jasonyunjoonpark
jasonyunjoonpark / Course.sol
Created January 4, 2018 19:11
Course registration contract with a variable fee amount that can only be set by the deployer of contract. Allows people to sign up by paying fee.
pragma solidity ^0.4.18;
contract Course {
address owner;
uint fee;
struct personalInfo {
string name;
uint age;
bool active;