getVaultShares
Get the vault share balance for a wallet. Shares represent your stake in the Zyfai Vault.
Signature
getVaultShares(
userAddress?: string,
chainId?: SupportedChainId
): Promise<VaultSharesResponse>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userAddress | string | ❌ | User address to check (defaults to connected wallet) |
chainId | SupportedChainId | ❌ | Chain ID (default: 8453 - Base) |
Returns
Vault shares balance and token symbol
Return Type
interface VaultSharesResponse {
success: boolean;
shares: bigint;
symbol: string;
}
Example
// Get shares for connected wallet
const { shares, symbol } = await sdk.getVaultShares();
console.log(`Balance: ${shares} ${symbol}`);
// Get shares for specific address
const info = await sdk.getVaultShares("0xUser...");
console.log(`User has ${info.shares} vault shares`);
Check Before Withdrawal
// Verify you have shares before withdrawing
const { shares } = await sdk.getVaultShares();
if (shares > 0n) {
const withdraw = await sdk.vaultWithdraw();
console.log("Withdrawal requested:", withdraw.withdrawKey);
} else {
console.log("No shares to withdraw");
}
Notes
- If no
userAddressis provided, uses the connected wallet address - Shares are returned as
bigintin the smallest unit (wei) - The
symbolis the vault's share token symbol (e.g., "zyUSDC") - Shares are minted when you deposit via vaultDeposit
- Shares are burned when you withdraw via vaultWithdraw