Last active
February 28, 2020 01:41
-
-
Save octalmage/7bf235bb7d0a12633eb24adf2bb0e6ce to your computer and use it in GitHub Desktop.
IOST ICO Example
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
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; |
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
{ | |
"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