Skip to content

Instantly share code, notes, and snippets.

@kobigurk
Last active August 29, 2015 14:20
Show Gist options
  • Save kobigurk/19265d90e835d033680a to your computer and use it in GitHub Desktop.
Save kobigurk/19265d90e835d033680a to your computer and use it in GitHub Desktop.
contract token {
mapping (address => uint) balances;
// Initializes contract with 10 000 tokens to the creator of the contract
function token() {
balances[msg.sender] = 10000;
}
// Very simple trade function
function sendToken(address receiver, uint amount) returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
return true;
}
// Check balances of any account
function getBalance(address account) returns(uint balance){
return balances[account];
}
}
var abi = [ { "constant" : false, "inputs" : [ { "name" : "receiver", "type" : "address" }, { "name" : "amount", "type" : "uint256" } ], "name" : "sendToken", "outputs" : [ { "name" : "sufficient", "type" : "bool" } ], "type" : "function" }, { "constant" : false, "inputs" : [ { "name" : "account", "type" : "address" } ], "name" : "getBalance", "outputs" : [ { "name" : "balance", "type" : "uint256" } ], "type" : "function" } ]
var contract = eth.contract(abi);
var instance = new contract('0xe7810c04a378e82ca42f125ccef2dc4b279a7bca');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment