Skip to main content
Deposit ERC20 tokens into the Monaco Protocol vault for trading and other operations.

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:
If the deposit cannot be routed to margin safely (for example, an unsupported asset or temporarily unavailable margin routing), it falls back to spot silently. The encoding is handled automatically by 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:
Balances provide current holdings and include 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

  1. Always authenticate first - Login before any vault operations
  2. Get asset IDs from trading pairs - Use sdk.market.getTradingPairBySymbol() or sdk.market.getPaginatedTradingPairs() to get valid asset IDs
  3. Check allowances - Use needsApproval() to avoid unnecessary approval transactions
  4. Handle errors gracefully - Check for ASSET_NOT_FOUND errors if using invalid asset IDs
  5. Verify balances - Check vault balances after deposits

Troubleshooting

Asset Not Found Error

If you get an ASSET_NOT_FOUND error, make sure you’re using a valid asset ID from a trading pair:

Approval Required Error

Insufficient Balance

Transaction Failed