Skip to content

Instantly share code, notes, and snippets.

@octalmage
Last active February 28, 2020 01:41
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 octalmage/7bf235bb7d0a12633eb24adf2bb0e6ce to your computer and use it in GitHub Desktop.
Save octalmage/7bf235bb7d0a12633eb24adf2bb0e6ce to your computer and use it in GitHub Desktop.
IOST ICO Example
const TOKEN = 'TIX';
const IOST_COST = '.1';
const TOKEN_DECIMALS = 8;
class ICO {
init() {
// Runs on deploy.
}
// Remove to disable updates.
can_update(data) {
return blockchain.requireAuth(blockchain.contractOwner(), 'active');
}
buy(amount, buyFor) {
const depositArgs = [
'iost',
tx.publisher, // Who's paying?
blockchain.contractName(), // Where to transfer?
new Float64(amount).multi(IOST_COST), // IOST amount.
`IOST exchanged for ${TOKEN}!`,
];
blockchain.call('token.iost', 'transfer', depositArgs);
const transferArgs = [
TOKEN.toLowerCase(),
blockchain.contractName(),
buyFor,
amount.toFixed(TOKEN_DECIMALS).toString(),
'Thanks for trading!',
];
blockchain.callWithAuth('token.iost', 'transfer', transferArgs);
}
}
module.exports = ICO;
{
"lang": "javascript",
"version": "1.0.0",
"abi": [
{
"name": "buy",
"args": [
"number",
"string"
],
"amountLimit": [
{
"token": "iost",
"val": "10000"
},
{
"token": "ram",
"val": "1000"
}
]
},
{
"name": "can_update",
"args": [
"string"
],
"amountLimit": [
{
"token": "ram",
"val": "1000"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment