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 transactional payload for depositing into a vault that includes optional deposit fee for wallets
Show all user positions across different vaults
Run the tutorial code
Clone or download tutorial code
git clone https://github.com/WallfacerLabs/js-examples.gitgit clone https://github.com/WallfacerLabs/python-examples.gitCreate virtual environment and install dependencies:
cd js_examples/
npm installcd python_examples/
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtSet your API key as an environment variable:
export VAULTS_FYI_API_KEY="your_api_key_here"Run
npm run wallet_integrationpython wallet_integration.pyStep 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)
Last updated
