Skip to content

Instantly share code, notes, and snippets.

@hendrawd
Created March 19, 2018 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrawd/f94a9376fc09df57830ed0c87fb875e7 to your computer and use it in GitHub Desktop.
Save hendrawd/f94a9376fc09df57830ed0c87fb875e7 to your computer and use it in GitHub Desktop.
Code for solidity, a programming language to deploy smart contract to ethereum platform. This demonstrate how to create, and transfer balance from one account to other account. Online IDE can be found here: http://remix.ethereum.org/
pragma solidity ^0.4.0;
/*
Currency that can only be issued by its creator and transferred to anyone
*/
contract DragonStone {
address public creator;
mapping (address => uint) public balances;
// event that notifies when a transfer has completed
event Delivered(address from, address to, uint amount);
function DragonStone() {
creator = msg.sender;
}
function create(address receiver, uint amount) {
if (msg.sender != creator) throw;
balances[receiver] += amount;
}
function transfer(address receiver, uint amount) {
if (balances[msg.sender] < amount) throw;
balances[msg.sender] -= amount;
balances[receiver] += amount;
Delivered(msg.sender, receiver, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment