From 2172a25fb122001eae43fe8ad770a9d121056062 Mon Sep 17 00:00:00 2001 From: Renzo <rontivero@ultimamillasa.com.ar> Date: Thu, 14 May 2020 18:25:10 -0300 Subject: [PATCH] Send TX Celo --- api/controllers/CeloController.js | 39 +++++++++++++++++++++++++++++++ config/routes.js | 2 ++ 2 files changed, 41 insertions(+) diff --git a/api/controllers/CeloController.js b/api/controllers/CeloController.js index 94a245c..709d6d6 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 e4a41cb..8023462 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', + /*************************************************************************** * * -- GitLab