Balances
This part of the cookbook contains everything related to Keypom balances. This balance acts like a debit card, where you deposit $NEAR up front and create drop and interact with Keypom without needing to attach deposits to everything you do. For more on balances, see here.
Getting Started
For the cookbook, you will need the following installed.
Ensure that you have initialized Keypom using the initKeypom function prior to running any of the SDK examples. For more info on this, see the introduction page
Viewing User Keypom Balances
To view your Keypom balance, you can use the following. This will allow you to decipher if you need to add more $NEAR to your balance before creating a drop.
- 🔑 Keypom SDK
- 🦀 Rust Function Prototypes
// Query for the drop information for a specific drop
const userBal = await getUserBalance({
accountId: "benjiman.testnet",
})
console.log('userBal: ', userBal)
pub fn get_user_balance(
&self,
account_id: AccountId
) -> U128
Adding to Keypom Balances
If you don't have sufficient funds to create your drop, you may add more $NEAR to your balance using the following. When specifying the amount to add, you can use amountNear or amountYocto to add in NEAR or yoctoNEAR respectively.
- 🔑 Keypom SDK
- 🦀 Rust Function Prototypes
await addToBalance({
account: fundingAccount,
amountNear: "5"
});
// Attached deposit will be added to predecessor's balance
pub fn add_to_balance(&mut self)
Withdrawing from Keypom Balance
If you are confident you no longer need Keypom or simply wish to withdraw your Keypom balance back into your NEAR wallet, you can use the following:
- 🔑 Keypom SDK
- 🦀 Rust Function Prototypes
await withdrawBalance({
account: fundingAccount
})
// Prececessor's balance will be withdrawn to their NEAR wallet
pub fn add_to_balance(&mut self)