-
-
Save anonymous/a3f54b293e2f0757b4c4f5165eb8655f to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Coin { | |
// The keyword "public" makes those variables | |
// readable from outside. | |
// declares a state variable of type address that | |
// is publicly accessible, | |
// does not allow any arithmetic operations. It is | |
// suitable for storing addresses of contracts or | |
// keypairs belonging to external persons | |
address public minter; | |
mapping (address => uint) public balances; | |
// Events allow light clients to react on | |
// changes efficiently. | |
event Sent(address from, address to, uint amount); | |
// This is the constructor whose code is | |
// run only when the contract is created. | |
function Coin() { | |
minter = msg.sender; | |
} | |
function mint(address receiver, uint amount) { | |
if (msg.sender != minter) return; | |
balances[receiver] += amount; | |
} | |
function send(address receiver, uint amount) { | |
if (balances[msg.sender] < amount) return; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
Sent(msg.sender, receiver, amount); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* collection of code (its functions) and data (its state) | |
* that resides at a specific address on the Ethereum blockchain. | |
* think of it as a single slot in a database that can be | |
* queried and altered by calling functions of the code that | |
* manages the database | |
* **/ | |
contract SimpleStorage { | |
//declares a state variable called storedData of type | |
//uint (unsigned integer of 256 bits) | |
uint storedData; | |
function set(uint x) { | |
storedData = x; | |
} | |
function get() constant returns (uint retVal) { | |
return storedData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment