Skip to content

Instantly share code, notes, and snippets.

@octalmage
Last active Feb 28, 2020
Embed
What would you like to do?
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