Skip to content

Instantly share code, notes, and snippets.

View yhuag's full-sized avatar
:octocat:
BUIDL

HU Yao-Chieh yhuag

:octocat:
BUIDL
View GitHub Profile
@yhuag
yhuag / Call.sol
Created August 11, 2018 10:33
Call to Math with solidity "call"
pragma solidity ^0.4.24;
contract Math {
// Answer
uint public ans;
// Module #0
function plus(uint _n1, uint _n2) public { ans = _n1 + _n2; }
// Module #1
function minus(uint _n1, uint _n2) public { ans = _n1 - _n2; }
// Module #2
pragma solidity ^0.4.24;
contract Math {
uint public ans;
function add(uint a,uint b) public {
ans = a + b;
}
}
pragma solidity ^0.4.24;
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
contract Payment {
using SafeMath for uint;
mapping (address => uint) public deposits;
@yhuag
yhuag / Token.sol
Created July 29, 2018 05:22
Demonstration for Workshop: Write and deploy your first smart contract in less than 30 minutes
/*
* Credit to: Ethereum
* Orginal source: https://www.ethereum.org/token
*/
pragma solidity ^0.4.13;
contract Token {
mapping (address => uint256) public balances;
@yhuag
yhuag / Library.sol
Last active July 5, 2018 16:48
Modularized smart contract: Library
pragma solidity ^0.4.24;
//// All Modules ////
contract Math {
// Module #0
function plus(uint _n1, uint _n2) public pure returns (uint) { return _n1 + _n2; }
// Module #1
function minus(uint _n1, uint _n2) public pure returns (uint ans) { return _n1 - _n2; }
// Module #2
@yhuag
yhuag / Multi.sol
Last active July 1, 2018 13:50
Modularized smart contract: Multiple inheritance
pragma solidity ^0.4.24;
//// All Modules ////
// Module #0
contract CanPlus {
function plus(uint _n1, uint _n2) public pure returns (uint ans) { return _n1 + _n2; }
}
// Module #1
contract CanMinus {
@yhuag
yhuag / Gating.sol
Created July 1, 2018 11:58
Modularized smart contract: Gating
pragma solidity ^0.4.24;
// @title Modularized smart contract: Gating
// @author Hu Yao-Chieh (yhuag@ust.hk)
// @dev This smart contract is modularized by switching on/off a specific module via modifier access control mapping.
contract Gating {
address owner;
mapping (uint => bool) public enabled;
// Constructor
pragma solidity ^0.4.21;
// @title MAR mode: Module-Agnostic Rendering Mode (Module)
// @author Jeff Hu
// @dev This smart contract is an atomic callable stub
contract M {
bool public value = false;
function setTrue() public {
value = true;
pragma solidity ^0.4.21;
// @title MAR mode: Module-Agnostic Rendering Mode (Core)
// @author Jeff Hu
// @dev This smart contract is modularized via a module agnostic execution scheme
contract C {
address public M_addr; // The deployed address of the module M
string public M_func; // The target function signature of module M
download: function () {
let csvContent = "data:text/csv;charset=utf-8,";
csvContent += document.getElementById("bulktextarea").value;
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "BitcoinKeys.csv");
document.body.appendChild(link);