Vesting and Freemint Contract
This page breaks down a TypeScript example that demonstrates how to create and interact with a vesting contract using the Glittr SDK.
1. Setup and Configuration
import {
Account,
GlittrSDK,
Fraction,
OpReturnMessage,
electrumFetchNonGlittrUtxos,
BitcoinUTXO,
Output,
addFeeToTx,
txBuilder,
BlockTxTuple,
} from "@glittr-sdk/sdk";
// Initialize SDK with network configuration
const NETWORK = "regtest";
const client = new GlittrSDK({
network: NETWORK,
apiKey: <your api key here>,
glittrApi: "https://devnet-core-api.glittr.fi",
electrumApi: "https://devnet-electrum.glittr.fi",
});
// Create three accounts for different roles
const account = new Account({...}); // Main account
const reserveAccount = new Account({...}); // Reserve account
const freeMintAccount = new Account({...}); // Free minting accountThe code starts by setting up the SDK client and creating three different accounts that will play different roles in the vesting contract.
2. Contract Creation
The deployVestingContract() function demonstrates how to create a vesting contract with the following characteristics:
Total supply cap: 1000 tokens
Divisibility: 100 (similar to decimals in other token standards)
Allocation:
100 tokens to receiver1
200 tokens to receiver2 (reserve)
700 tokens for free minting
The vesting schedule is quarterly:
Contract creation code:
3. Minting Operations
The code includes two types of minting:
Vested Minting
Free Minting
Call the following function using account that don't have vesting allocation a.k.a the freeMintAccount.
4. Asset Checking
The code provides two utility functions to check the status of assets:
Key Concepts
Vesting Schedule: The contract implements a linear vesting schedule where tokens are released in 25% increments over 4 blocks.
Allocation Types:
Direct allocation (vested)
Reserve allocation (vested)
Free mint allocation (unrestricted)
Asset Verification: The code includes methods to verify the status of both vested and free-minted assets through API calls.
Usage Flow
Create the contract using
createContract()Wait for vesting periods to unlock
Use
vestedMint()to claim vested tokensUse
freeMint()to mint from the free allocationVerify asset status using the checking functions
This example demonstrates a complete flow of creating and interacting with a vesting contract on the Glittr platform, including both restricted (vested) and unrestricted (free mint) token distributions.
Full Code Example
Last updated