Skip to main content
Version: Next

Trial Account Drops

This part of the cookbook contains a quick overview on how to create a trial account drop.

Getting Started

For the cookbook, you will need the following installed.

  1. Node JS
  2. Keypom JS SDK
note

These scripts will not run without the proper setup shown in the introduction page.

Creating a Trial Account Drop

When creating a trial account drop, there are 3 main parameters to define. The first is callableContracts, indicating what contracts the trial account can call. This will prevent rugging from the funder's perspective. Next is maxAttachableNearPerContract which just outlines how much $NEAR can be attached to any function call on any of the aforementioned contracts. The order of this is the same as the order defined in callableContracts. Lastly is the callableMethods parameter, which defines what methods the trial account is allowed to call on the allowed contracts. A * indicated any contract is callable.

When creating the drop, the trial account's balance is then defined by its starting balance and ending balance, known as the startingBalanceNEAR and trialEndFloorNEAR respectively.

tip

A short explanation for Rust version is found below the codeblock.

// What contracts can the trial account call?
const callableContracts = [
'guest-book.examples.keypom.testnet',
'v1.social08.testnet'
]
// What is the maximum amount of $NEAR that can be attached to a call for each callable contract?
// 1 NEAR for guestbook, 2 NEAR for NEAR social
const maxAttachableNEARPerContract = [
'1',
'2'
]
// What methods can the trial account call?
// Any function can be called on either contracts.
const callableMethods = [
['*'],
['*']
]

const wasmDirectory = `${require('path').resolve(__dirname, '..')}/trial-accounts/ext-wasm/trial-accounts.wasm`
const {keys} = await createTrialAccountDrop({
account: fundingAccount,
numKeys: 1,
contractBytes: [...readFileSync(wasmDirectory)],
// How much $NEAR should be made available to the trial account when it's created?
startingBalanceNEAR: 2.5,
callableContracts,
callableMethods,
maxAttachableNEARPerContract,
// Once the trial account has spent this much $NEAR, the trial will be over.
trialEndFloorNEAR: 1.25
})

console.log(keys)

At its core, a trial account drop is just a FunctionCall drop that uses the function calls to creates an account with a contract deployed to it, and then calls the setup method on that newly created account. Since there is no createTrialAccountDrop equivalent baked into the protocol, you will need to manually setup all the FC drop arguments.

The first half, creating an account with a contract deployed to it, is done using the create_account_advanced method. If you have used a custom drop root using the root_account_id parameter, you must ensure the contract deployed to that account has the create_account_advanced method exposed.

A sample set of arguments passed into create_account_advanced for a trial account drop can be found here.

The second half is the setup method, which defines the trial account's allowed contracts, methods and max deposits etc. It's important to understand that the setup method is being called on the contract deployed to the trial account during create_account_advanced. To do this, the receiver_to_claimer must be set to true.

A sample set of arguments passed into setup can be found here.


Delete Drop

A drop can be deleted manually at any time using deleteDrops. This will refund all unclaimed key balances back to the drop funder's Keypom balance.

The Keypom contract does not have a deleteDrops equivalent function. Behind the scenes of the SDK, the keys are being collected, refunded and then deleted.

The first step in this process is to use get_key_supply_for_drop. Once the total key supply is found, 50 keys at a time are retrieved using get_keys_for_drop and refunding their associated assets and deleting the keys using refund_assets and delete_keys respectively.

// Get all the drops for a given user
let drops = await getDrops({accountId: "minqi.testnet"});

// Delete all the drops currently funded by `minqi.testnet`
await deleteDrops({
account: fundingAccount,
drops
})

// Delete 2 seperate drops given their IDs
await deleteDrops({
account: fundingAccount,
dropIds: ["123123123123123", "12391238012380123"]
})