Skip to content

Instantly share code, notes, and snippets.

@Ankarrr
Created November 20, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ankarrr/9d4135a835b8fbda63025e403f222cb5 to your computer and use it in GitHub Desktop.
Save Ankarrr/9d4135a835b8fbda63025e403f222cb5 to your computer and use it in GitHub Desktop.
// 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