Getting Started
Quick Start
Step 1: Initialize the SDK
import { YieldFiSDK } from "yieldfi-sdk";
// Initialize SDK (async)
const sdk = await YieldFiSDK.create({
gatewayUrl: "https://gw.yield.fi",
partnerId: "your-partner-id", // Optional: for tracking
});Step 2: Authenticate a User
// 1. Generate a nonce for the user's address
const nonce = await sdk.auth.generateNonce({
address: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
});
// 2. Sign the message with the user's wallet
// Using ethers.js v6
import { ethers } from "ethers";
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const signature = await signer.signMessage(nonce.message);
// Or using MetaMask directly
const signature = await window.ethereum.request({
method: "personal_sign",
params: [nonce.message, userAddress],
});
// 3. Login with the signature
const authResponse = await sdk.auth.login({
address: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
signature,
message: nonce.message,
});
// 4. Store tokens (you must manage storage yourself)
localStorage.setItem("accessToken", authResponse.accessToken);
localStorage.setItem("refreshToken", authResponse.refreshToken);
localStorage.setItem("user", JSON.stringify(authResponse.user));Step 3: Query Vaults
Step 4: Query Transactions (Authenticated)
Step 5: Handle Errors
Complete Example
Next Steps
Last updated