Skip to main content

Staking/Claiming Example

In this demonstration, we will use Typescript to illustrate a straightforward example. Our objective is to walk you through the process of staking/claiming assets with the Client SDK.

Stake or Harvest Assets

Contants

constant.ts

export const YOUR_STAKE_COLLECTION = number;
export const YOUR_UNIT = "";
export const YOUR_TIME_TO_LOCK = number;

Setup

Create a file named api.ts

import { anvil } from "@ada-anvil/sdk-client";

// Setup API Key provided by Anvil
anvil.config.authenticate("client_XXXXXXXXX");

Stake Assets

export async function stake({
quantity,
depositIndex,
}: {
quantity: number;
depositIndex: number | undefined;
}) {
try {
await anvil.wallet.connect("eternl"); // One of: [nami, eternl, flint, gerowallet, typhoncip30, nufi, lace]
const transactionHash = await anvil.staking.stakeAssets({
stakeCollectionId: YOUR_STAKE_COLLECTION,
assets: [{ unit: YOUR_UNIT, quantity }],
seconds: YOUR_TIME_TO_LOCK,
options: {
depositIndex,
},
});

return transactionHash;
} catch {
console.log("YOUR ERROR HANDLING");
}
}

Claim Assets

export async function harvest({ stakeId }: { stakeId: number }) {
try {
await anvil.wallet.connect("eternl"); // One of: [nami, eternl, flint, gerowallet, typhoncip30, nufi, lace]
const transactionHash = await anvil.staking.harvestStake({
stakeId,
claim: true,
});

return transactionHash;
} catch {
console.log("YOUR ERROR HANDLING");
}
}