Quick Setup
Depositing Directly to Margin Collateral
By default,vault.deposit() credits your spot wallet. Pass "margin" as the optional fourth argument to route the on-chain deposit straight into your parent margin account’s collateral — skipping the separate transferCollateralToParentMarginAccount step:
encodeDepositApplicationData() — existing spot deposits are byte-identical to before.
If you call the vault contract directly instead of through the SDK, encode the deposit’s applicationData with encodeDepositApplicationData(clientId, target) from @0xmonaco/contracts. A spot deposit carries the bare client ID. A margin deposit must carry exactly {"clientId":"<clientId>","depositTarget":"MARGIN"}, byte for byte, with no extra whitespace or keys and a client ID of 1–64 letters, digits, _ or -. The only other accepted JSON form is {"clientId":"<clientId>","depositTarget":"INSURANCE_FUND"}, which Monaco uses to top up its insurance fund. Any other payload that starts with { is not guessed at: it is credited to the spot wallet of Monaco’s default application, not yours.
Understanding Asset IDs
Monaco uses asset IDs (UUIDs) for all vault operations. This provides a consistent interface regardless of the underlying token contract.
Trading pairs are the easiest place to discover asset IDs before a user has a balance:
assetId for assets already in the account:
Step-by-Step Deposit Process
1. Authenticate
Authentication is required before any vault operations:2. Get Asset Information
Retrieve the asset you want to deposit from a trading pair:3. Check Current Allowance
Before approving, check if approval is needed:4. Approve Token Spending
Grant vault permission to spend your tokens:5. Execute Deposit
Transfer tokens to the vault:6. Verify Deposit
Check your vault balance:Complete Example
Error Handling
Best Practices
- Always authenticate first - Login before any vault operations
- Get asset IDs from trading pairs - Use
sdk.market.getTradingPairBySymbol()orsdk.market.getPaginatedTradingPairs()to get valid asset IDs - Check allowances - Use
needsApproval()to avoid unnecessary approval transactions - Handle errors gracefully - Check for
ASSET_NOT_FOUNDerrors if using invalid asset IDs - Verify balances - Check vault balances after deposits
Troubleshooting
Asset Not Found Error
If you get anASSET_NOT_FOUND error, make sure you’re using a valid asset ID from a trading pair:

