Frontend Integration

Voltr Protocol - Frontend Integration Guide for Vault Deposits & Withdrawals

This guide explains how to integrate deposit and withdrawal functionality into your frontend application for the Voltr Protocol.

Setup

Import the required dependencies:

import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
import { VoltrClient } from "@voltr/vault-sdk";
import { BN } from "@coral-xyz/anchor";
import {
  createAssociatedTokenAccountIdempotentInstruction,
  createSyncNativeInstruction,
  createCloseAccountInstruction,
  getAssociatedTokenAddressSync,
  NATIVE_MINT,
} from "@solana/spl-token";

Initialize the client:

const connection = new Connection(rpcEndpoint);
const client = new VoltrClient(connection);

// Initialize vault constants
const VAULT_ADDRESS = new PublicKey("your-vault-address");
const VAULT_ASSET_MINT = new PublicKey("your-asset-mint");

Deposit Implementation

1. Create Deposit Component

2. Handle SOL/SPL Token Deposits

3. Create Deposit UI

Withdrawal Implementation

1. Create Withdrawal Component

2. Handle Token Withdrawals

3. Create Withdrawal UI

Important Considerations

1. Token Account Management

  • Always check if token accounts exist before transactions

  • Create ATAs idempotently to prevent errors

  • Handle SOL wrapping/unwrapping correctly

  • Clean up temporary token accounts

2. Transaction Handling

  • Implement proper error handling

  • Show loading states during transactions

  • Provide clear feedback to users

  • Handle transaction confirmation properly

3. User Experience

  • Display proper decimal places for amounts

  • Show available balance

  • Implement input validation

  • Display transaction fees

  • Show transaction status updates

4. Error Cases

Handle common error scenarios:

For additional support or questions, refer to the Voltr SDK documentation or example scripts.

Last updated