Skip to main content

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

ParameterTypeRequiredDescription
userAddressstringUser address to check (defaults to connected wallet)
chainIdSupportedChainIdChain 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 userAddress is provided, uses the connected wallet address
  • Shares are returned as bigint in the smallest unit (wei)
  • The symbol is 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