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
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { | |
uint oldValue = allowed[msg.sender][_spender]; | |
if (_subtractedValue > oldValue) { | |
allowed[msg.sender][_spender] = 0; |
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
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; |
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
function approve( address _spender, uint256 _value, bytes _data ) public returns (bool) { | |
require(_spender != address(this)); | |
super.approve(_spender, _value); | |
require(_spender.call(_data)); | |
return true; | |
} | |
function transfer( address _to, uint256 _value, bytes _data ) public returns (bool) { | |
require(_to != address(this)); | |
super.transfer(_to, _value); | |
require(_to.call(_data)); |
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
async withdraw(claimant, mgcc) { | |
const txObject = { | |
from: claimant, | |
to: this.tokenContractAddress, | |
gas: 120000, | |
value: 0, | |
}; | |
return new Promise((resolve, reject) => { | |
this.tokenContract.approve.sendTransaction( | |
this.exchangeContractAddress, |
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
GoCryptobotCoinERC827 internal coin; | |
function setCoinContract(address _address) external onlyOwnerOrOperator { | |
GoCryptobotCoinERC827 _contract = GoCryptobotCoinERC827(_address); | |
coin = _contract; | |
} | |
uint8 constant FEE_RATE = 5; | |
function withdraw(address _claimant, uint256 _mgcc) public whenNotPaused { | |
require(coin.allowance(_claimant, this) >= _mgcc); | |
require(coin.transferFrom(_claimant, coinStorage, _mgcc)); | |
uint256 exchange = (_convertToWei(_mgcc) / 100) * (100 - FEE_RATE); |
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
var SDK = require("codechain-sdk"); | |
var sdk = new SDK({ server: "http://localhost:8080" }); | |
var address = "ccaqqqk7n0a0w69tjfza9svdjzhvu95cpl29ssnyn99ml8nvl8q6sd2c7qgjejfc"; | |
var assetMintTransaction = sdk.core.createAssetMintTransaction({ | |
scheme: { | |
shardId: 0, | |
metadata: JSON.stringify({ | |
name: "Wow Token", |
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
var SDK = require("codechain-sdk"); | |
var sdk = new SDK({ server: "http://localhost:8080" }); | |
sdk.rpc.account.create("my-secret").then(function (account) { | |
console.log(account); // string that starts with "ccc". For example: cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7 | |
}).catch(console.error); |
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
# npm | |
npm install codechain-sdk | |
# yarn | |
yarn add codechain-sdk |
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
sdk.rpc.account.create("passphrase").then(function (account) { | |
console.log(account); // cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7 | |
}).catch(console.error); |
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
var secret = "ede1d4ccb4ec9a8bbbae9a13db3f4a7b56ea04189be86ac3a6a439d9a0a1addd"; | |
var passphrase = "satoshi"; | |
sdk.rpc.account.importRaw(secret, passphrase).then(function (account) { | |
console.log(account); // cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7 | |
}).catch(console.error); |