vaults.fyi
  • General
    • 🏦Overview
    • 💡Use Cases
      • For Wallets and Apps
        • Monetize Your Wallet Seamlessly & Securely
      • For Analysts
      • For Protocols & Product Teams
    • 🔎Methodology
      • vaults.fyi USD benchmark rate
      • vaults.fyi ETH benchmark rate
    • ❓FAQ
      • Vault requirements for inclusion on vaults.fyi
    • 🤖AI
  • API
    • Introduction
      • Market data
      • Transactional support
      • Portfolio tracking
      • Personalized insights
    • Quickstart
    • Tutorials
      • Wallet Integration
      • Data Analytics
    • SDK
  • Endpoints
    • General
    • Detailed Vaults
    • Historical
    • Portfolio
    • Transactions
    • Legacy (v1) endpoints
      • v1 Market data
        • Get historical data
          • Get historical APY and TVL data on single vault over timestamp range
          • Get historical APY on single vault over timestamp range
          • Get historical TVL on single vault at single timestamp
          • Get historical APY on single vault at single timestamp
        • Get data for multiple vaults
        • Get data on single vault
          • Get APY on single vault
        • Get benchmark rates
        • Get supported vaults, networks & tokens
          • /vaults
          • /networks
          • /tokens
          • /tags
      • v1 Contextual insights
        • Top vault options for address
        • Get single top option for address
        • [Etherscan cards] Get top USD, top ETH vault for address
      • v1 Generate payloads
        • Prepare calldata
          • Supply/Deposit
          • Withdraw/Redeem
            • Request redeem
            • Claim redeem
          • Claim rewards
        • Get contract interaction details
        • Get supported assets
        • Get supported vaults
      • v1 Position tracking
        • Get user balances
        • Get user positions
        • Get list of past vault txns by user address
        • Get estimated returns for user's vault position
  • Case Studies
    • Kraken Wallet
    • Etherscan Cards
    • Gauntlet
  • Plans
    • Credits
      • Credits (v1 endpoints)
  • Links
    • vaults.fyi
    • X
    • Farcaster
    • Wallfacer Labs
Powered by GitBook
On this page
  • Run the tutorial code
  • Step by step
  1. API
  2. Tutorials

Wallet Integration

Example code + mini tutorial showing Portfolio and Transactional integrations with Vaults.fyi

The example will:

  • Check user balances (idle assets) and display them in a formatted table

  • Display the best deposit options filtered for USDC/USDS only

  • Generate a transaction payload for the 3rd vault option with full transaction details

  • Show all user positions across different vaults

Run the tutorial code

  1. Clone or download tutorial code

git clone https://github.com/WallfacerLabs/js-examples.git
git clone https://github.com/WallfacerLabs/python-examples.git

  1. Create virtual environment and install dependencies:

cd js_examples/
npm install
cd python_examples/
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

  1. Set your API key as an environment variable:

export VAULTS_FYI_API_KEY="your_api_key_here"

Run

npm run wallet_integration
python wallet_integration.py

Step by step

1. SDK Initialization

import pkg from '@vaultsfyi/sdk';
const { VaultsSdk } = pkg;

// Initialize the SDK
const vaultsFyi = new VaultsSdk({
  apiKey: process.env.VAULTS_FYI_API_KEY,
 
});
from vaultsfyi import VaultsSdk

client = VaultsSdk(api_key="your_api_key_here")

2. Viewing User Balances

async function getUserBalances() {
  const idleAssets = await vaultsFyi.getIdleAssets({
    path: { userAddress: '0xdB79e7E9e1412457528e40db9fCDBe69f558777d' }
  });
  
  return idleAssets;
}
idle_assets = client.get_idle_assets(user_address)

3. Finding Best Deposit Options

async function getBestDepositOptions() {
  const depositOptions = await vaultsFyi.getDepositOptions({
    path: { userAddress: '0xdB79e7E9e1412457528e40db9fCDBe69f558777d' },
    query: { allowedAssets: ['USDC', 'USDS'] }
  });
  
  return depositOptions;
}
deposit_options = client.get_deposit_options(
    user_address,
    allowed_assets=["USDC", "USDS"]
)

4. Generating Deposit Transactions

async function generateDepositTransaction(vaultAddress, amount, userAddress, network, assetAddress) {
  const transaction = await vaultsFyi.getActions({
    path: { 
      action: 'deposit',
      userAddress: userAddress,
      network: network, 
      vaultAddress: vaultAddress
    },
    query: { 
      amount: amount,
      assetAddress: assetAddress,
      simulate: false
    }
  });
  
  return transaction;
}
transaction = client.get_actions(
    action="deposit",
    user_address=user_address,
    network=network,
    vault_address=vault_address,
    amount=amount,
    asset_address=asset_address,
    simulate=False
)

5. Viewing User Positions

async function getUserPositions() {
  const positions = await vaultsFyi.getPositions({
    path: { userAddress: '0xdB79e7E9e1412457528e40db9fCDBe69f558777d' }
  });
  
  return positions;
}
  
positions = client.get_positions(user_address)

PreviousTutorialsNextData Analytics

Last updated 17 hours ago

Page cover image