diff --git a/api/controllers/CeloController.js b/api/controllers/CeloController.js index 94a245cda4fd95a879a3fbb5b797843bb835077e..709d6d6e48ec71afe2f189f30358c9d9d2afe661 100755 --- a/api/controllers/CeloController.js +++ b/api/controllers/CeloController.js @@ -28,5 +28,44 @@ module.exports = { return res.json(balance); }, + send : async function (req, res){ + sails.log('Send()'); + sails.log(req.body) + // 10. Get your account + let from = req.body.from + + // 11. Add your account to ContractKit to sign transactions + kit.addAccount(req.body.private_key) + + // 12. Specify recipient Address + let to = req.body.to + + // 13. Specify an amount to send + let amount = req.body.value + + // 14. Get the Gold Token contract wrapper + let goldtoken = await kit.contracts.getGoldToken() + + // 15. Transfer gold from your account to anAddress + let tx = await goldtoken.transfer(to, amount).send({from: from}) + + // 16. Wait for the transaction to be processed + let receipt = await tx.waitReceipt() + + // 17. Print receipt + console.log('Transaction receipt: %o', receipt) + + // 18. Get your new balance + let balance = await goldtoken.balanceOf(from) + + // 19. Print new balance + console.log(`Your new account balance: ${balance.toString()}`) + + return res.json({ + status: 'ok', + tx: receipt + }) + } + }; diff --git a/config/routes.js b/config/routes.js index e4a41cb874d18bbc5cc9e29de3a19808d1a6596d..802346259332344c6d070255c839b73dbef414c4 100755 --- a/config/routes.js +++ b/config/routes.js @@ -68,6 +68,8 @@ module.exports.routes = { 'POST /bfa/stamp' : 'BfaController.stamp', 'POST /bfa/send' : 'BfaController.send', + 'POST /celo/send' : 'CeloController.send', + /*************************************************************************** * *