How to approve and deposit funds for Kwil databases.
Before a user can create a database and execute insert/update/delete queries, they must fund their database.
All funding interactions begin by calling the
.getFunder()method on the Kwil class.
.getFunder()accepts to arguments: a Kwil funding pool address and an ethereum provider.
// get funder
const funder = await kwil.getFunder(ethereum_signer);
Before depositing funds to the funding pool, the user must approve funds to be spent on their behalf.
// approve funds
const approve = await funder.approve(ethers.BigNumber.from("1000000000"));
After funds are approved, they may be deposited into the Kwil funding pool.
// Deposit funds
const deposit = await funder.deposit(ethers.BigNumber.from("1000000000"));
To see the available funds in a user's wallet, use the
// Get wallet balance
const walletBalance = await funder.getBalance("wallet_address");
// Return the current allowance
const allowance = await funder.getAllowance("wallet_address");
To see the total amount of funds that have been deposited by an individual wallet, use the
.getDepositedBalance()method. Note that this is different than the funds available to be spent that is returned from getAccount.
// Return the deposited balance
const depositedFunds = await funder.getDepositedBalance("wallet_address");
To view the token address in the selected funding pool, use the
// Get token address in funding pool
const tokenAddress = await funder.getTokenAddress();