Created
November 20, 2020 15:57
-
-
Save Ankarrr/9d4135a835b8fbda63025e403f222cb5 to your computer and use it in GitHub Desktop.
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 ContractKit = require('@celo/contractkit'); | |
import ContractKit from '@celo/contractkit'; | |
// const phrase = 'nature hold lumber pizza grief badge danger boat oyster grit rifle cloth'; | |
const celoAddress = '0x897FF26e794Ba4F494D3C83C86fAFA3eB0DaaCD4'; | |
const privateKey = '0xce002e6b316387af656030dabfe1a4ec5bce375a010b9fa2075d434c1dee3477'; | |
const kit = ContractKit.newKit('https://alfajores-forno.celo-testnet.org'); | |
kit.addAccount(privateKey); | |
/** | |
* Get cUSD balance | |
*/ | |
const getCusdBalance = async () => { | |
// Get cUSDC balance | |
const totalBalance = await kit.getTotalBalance(celoAddress); | |
const cUsdBalance = totalBalance.cUSD.toNumber() / 1e18; | |
return cUsdBalance; | |
}; | |
/** | |
* Send cUSD | |
* @param {number} amount | |
* @param {string} destAddress | |
*/ | |
const sendCusd = async (amount, destAddress) => { | |
const stableToken = await kit.contracts.getStableToken(); | |
const amountWei = kit.web3.utils.toWei(amount.toString(), 'ether'); | |
const tx = await stableToken.transfer(destAddress, amountWei).send({ from: celoAddress }); | |
const receipt = await tx.waitReceipt(); | |
return receipt.transactionHash; | |
}; | |
module.exports = { celoAddress, getCusdBalance, sendCusd }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment