Skip to content

Instantly share code, notes, and snippets.

@TOMOAKI12345
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save TOMOAKI12345/8ad669e479c1d6d36b1b to your computer and use it in GitHub Desktop.

Select an option

Save TOMOAKI12345/8ad669e479c1d6d36b1b to your computer and use it in GitHub Desktop.
Token contract
// define token compiled code
var tokenCompiled = '606060405260405160208061025a8339016040526060805190602001505b8080602757506127105b600060005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055505b506101ef8061006b6000396000f30060606040526000357c01000000000000000000000000000000000000000000000000000000009004806390b98a1114610044578063bbd39ac01461007157610042565b005b61005b6004803590602001803590602001506100b3565b6040518082815260200191505060405180910390f35b610082600480359060200150610098565b6040518082815260200191505060405180910390f35b60006000506020528060005260406000206000915090505481565b600081600060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505410156100f557600090506101e9565b81600060005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600060005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055507f16cdf1707799c6655baac6e210f52b94b7cec08adcaf9ede7dfe8649da926146338484604051808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a1600190506101e9565b9291505056'
// define token ABI
var tokenABI = [{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"sendCoin","outputs":[{"name":"sufficient","type":"bool"}],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"coinBalanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"inputs":[{"name":"supply","type":"uint256"}],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"receiver","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"CoinTransfer","type":"event"}]
// define supply of tokens
var supply = 100;
// create token contract
var tokenFactory = web3.eth.contract(tokenABI);
var token = tokenContract.new(
supply,
{
from:web3.eth.accounts[1],
data:tokenCompiled,
gas: 2000000
}, function(e, contract){
console.log('hello callback')
if(!e) {
if(!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
else{
console.log(e);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment