Last active
August 29, 2015 14:20
-
-
Save kobigurk/19265d90e835d033680a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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]; | |
} | |
} |
This file contains hidden or 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
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