vaultClaim
Claim a completed withdrawal from the Zyfai Vault. Use this after your withdrawal request has been processed.
Signature
vaultClaim(
withdrawKey: string,
chainId?: SupportedChainId
): Promise<VaultClaimResponse>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
withdrawKey | string | ✅ | The withdraw key from vaultWithdraw() |
chainId | SupportedChainId | ❌ | Chain ID (default: 8453 - Base) |
Returns
Claim transaction result
Return Type
interface VaultClaimResponse {
success: boolean;
txHash: string;
claimed: boolean;
}
Example
// Request withdrawal first
const withdraw = await sdk.vaultWithdraw();
console.log("Withdraw requested:", withdraw.withdrawKey);
// If immediately claimable, claim now
if (withdraw.status === "claimable") {
const claim = await sdk.vaultClaim(withdraw.withdrawKey);
console.log("Claimed:", claim.txHash);
console.log("USDC returned to wallet");
} else {
console.log("Withdrawal pending, try claiming later with withdrawKey:", withdraw.withdrawKey);
}
Claim a Previous Withdrawal
// Claim using a saved withdrawKey
const claim = await sdk.vaultClaim("0x1234...withdrawKey");
console.log("Successfully claimed:", claim.txHash);
Error Handling
The method will throw an error if:
- The withdrawal has already been claimed
- The withdrawal is not yet claimable (still processing)
- The withdraw key is invalid
try {
const claim = await sdk.vaultClaim(withdrawKey);
console.log("Claimed successfully");
} catch (error) {
if (error.message.includes("already been claimed")) {
console.log("This withdrawal was already claimed");
} else if (error.message.includes("not yet claimable")) {
console.log("Please wait for processing to complete");
}
}
Notes
- Wallet must be connected via
connectAccount()before calling - The claimed USDC is sent directly to your connected wallet address
- Each withdraw key can only be claimed once