Vertex Docs
  • Getting Started
    • 📋Overview
    • 📜Table of Contents
    • 🚀Mission
    • ⚔️Vertex Edge
      • 1️⃣Vertex on Arbitrum
      • 2️⃣Blitz on Blast
        • Blitz Documentation
      • 3️⃣Vertex on Mantle
        • 🎆Trading Rewards
        • 📊Perpetual & Spot Market Specifications
        • 🖥️Open-Source Contracts
        • 🔌API
      • 4️⃣Vertex on Sei
        • 💰Trading Rewards
        • 📊Perpetual & Spot Market Specifications
        • 🖥️On-Chain Contracts
        • 🔌API
      • 5️⃣Vertex on Base
        • 💰Trading Rewards
        • 📊Perpetual & Spot Market Specifications
        • 💻Onchain Contracts
        • 🔌API
        • ✍️Create a Coinbase Smart Wallet
      • 6️⃣Vertex on Sonic
        • 💰Trading Rewards
        • 📊Perpetual & Spot Market Specifications
        • ⛓️On-Chain Contracts
        • 🔌API
      • 7️⃣Vertex on Abstract
        • 📊Market Specifications
        • ⛓️On-Chain Contracts
        • 🔌API
      • 8️⃣Bro.Trade on Berachain
        • ⛓️On-Chain Contracts
        • 🔌API
      • 9️⃣Vertex on Avalanche
        • 💰Trading Rewards
        • 📊Market Specifications
        • ⛓️On-Chain Contracts
        • 🔌API
  • Basics
    • 📽️Products
    • ⚡Technical Architecture
    • 🧵Universal Cross Margin
    • ✂️Isolated Margin
    • ℹ️Subaccounts & Health
    • ⏰Liquidations & Insurance Fund
    • 💵PnL Settlements
    • 📊Pricing (Oracles)
    • 💰Fees
    • 📈Funding Rates
    • 📅Market Specifications
    • ⚡One-Click Trading
    • 🔫Trigger Orders
    • 🗂️GMCI 30 & MEME Indices
    • 💰Trade & Earn
      • 🤝Maker Program
      • 🔁Cross-Chain VRTX Rewards
      • ❓Trading Rewards - FAQs
    • 🧑‍🤝‍🧑Referral Program
    • ⚒️Resources & Links
    • ❔FAQs
  • VRTX Token
    • 🎓VRTX Tokenomics
    • 📊Token Supply Distribution
  • More
    • 🌐Glossary
    • 🔬Contracts & Code Audits
    • 🦋Bug Bounties
    • 💽Data & Research
    • 🪟Maintenance Windows
    • 🏁Terms of Use
    • ✍️Statement of Risk
    • 🌍Restricted Territories
    • 📸Brand Assets
  • Tutorials
    • 🏁Quick Start
    • 🖱️One-Click Trading
    • ⚙️Trading Basics
    • ♾️Perpetuals
    • 🔮Spot
    • 🧑‍🤝‍🧑Multiple Accounts
    • 🔫TP/SL & Stop-Market
    • 💰Withdrawals
    • ⚡Fast Withdrawals
    • 🌉Cross-Chain Deposits
    • 🔄Lend, Borrow & Repay
    • ❤️Margin Health
    • 💧Pools
    • 💫VRTX Staking
    • ↔️Switching Chains
    • 🪙Trading Rewards
    • ✂️Shortcuts
  • Developer Resources
    • API
      • 🔌Endpoints
      • Gateway
        • Executes
          • Place Order
          • Place Isolated Order
          • Cancel Orders
          • Cancel Product Orders
          • Cancel And Place
          • Withdraw Collateral
          • Transfer Quote
          • Liquidate Subaccount
          • Mint LP
          • Burn LP
          • Link Signer
        • Queries
          • Status
          • Contracts
          • Nonces
          • Order
          • Orders
          • Subaccount Info
          • Isolated Positions
          • Market Liquidity
          • Symbols
          • All Products
          • Edge All Products
          • Market Prices
          • Max Order Size
          • Max Withdrawable
          • Max LP Mintable
          • Fee Rates
          • Health Groups
          • Linked Signer
          • Insurance
          • Min Deposit Rates
        • Signing
          • Examples
          • Q&A
      • Subscriptions
        • Authentication
        • Streams
        • Events
        • Rate limits
      • Archive (indexer)
        • Orders
        • Matches
        • Events
        • Summary
        • Candlesticks
        • Edge Candlesticks
        • Funding Rate
        • Interest & funding payments
        • Oracle Price
        • Perp Prices
        • Product Snapshots
        • Market Snapshots
        • Edge Market Snapshots
        • Maker Statistics
        • Merkle Proofs
        • Rewards
        • Referral Code
        • Liquidation Feed
        • Linked Signer Rate Limit
        • Subaccounts
        • Signatures
        • USDC Price
      • Trigger
        • Executes
          • Place Order
          • Cancel Orders
          • Cancel Product Orders
        • Queries
          • List Trigger Orders
      • V2
        • Assets
        • Pairs
        • APR
        • Orderbook
        • Tickers
        • Contracts
        • Trades
        • VRTX Token
      • Rate limits
      • Errors
      • Symbols
      • Depositing
      • Withdrawing (on-chain)
      • Integrate via Smart Contracts
      • Definitions / Formulas
    • Vertex Typescript SDK
      • Getting Started
      • How To
        • Create a Vertex client
        • Useful Common Functions
        • Query Markets & Products
        • Deposit Funds
        • Withdraw Funds
        • Manage Orders
      • User Guide
        • Client
          • Market
            • Place Order
            • Cancel Orders
            • Cancel Product Orders
            • Mint LP
            • Burn LP
            • Get All Markets
            • Get Latest Market Price
            • Get Market Liquidity
            • Get Open Subaccount orders
            • Get Historical Orders
            • Get Max Order Size
            • Get Max Mint LP
            • Get Candlesticks
            • Get Funding Rate
            • Get Product Snapshots
          • Spot
            • Approve Allowance
            • Deposit
            • Withdraw
            • Get Max Withdrawable
            • Get Token Contract for Product
            • Get Token Wallet Balance
            • Get Token Allowance
          • Perp
            • Get prices
          • Subaccount
            • Link Signer
            • Get Subaccount Linked Signer with Rate limits
            • Get Subaccount Summary
            • Get Subaccount Fee Rates
            • Get Subaccount Token Rewards
        • Engine Client
          • Executes
          • Queries
        • Indexer Client
          • Base Queries
          • Paginated Queries
        • Websocket
          • Executes
          • Queries
          • Subscriptions
        • Utilities
          • Contracts
          • Utils
      • API Reference
    • Vertex Python SDK
    • Vertex Rust SDK
    • Contracts
    • API/SDK Terms of Use
Powered by GitBook
On this page
  • Import the functions
  • Mint a mock ERC20 token for testing
  • Make a deposit
  • Query Subaccount balance
  • Full example
Export as PDF
  1. Developer Resources
  2. Vertex Typescript SDK
  3. How To

Deposit Funds

PreviousQuery Markets & ProductsNextWithdraw Funds

Last updated 2 months ago

Import the functions

We'll use a few of the , assuming that they are in a common.ts file. The withdraw step requires a nonce as the transaction is executed against the off-chain engine.

import { toFixedPoint } from '@vertex-protocol/utils';
// Change the import source as needed
import { getVertexClient, prettyPrintJson } from './common';

Mint a mock ERC20 token for testing

Grab a client object and mint mock tokens for the relevant product. This is only available on testnets for obvious reasons.

Minting is on-chain, so we wait for the transaction confirmation for chain state to propagate.

const vertexClient = await getVertexClient();
const { walletClient, publicClient } = vertexClient.context

// If you have access to `walletClient`, you can call `walletClient.account.address`
// directly instead of reaching into `vertexClient.context`
const address = walletClient!.account.address;
const subaccountName = 'default';
// 10 USDC (6 decimals)
const depositAmount = toFixedPoint(10, 6);

const mintTxHash = await vertexClient.spot._mintMockERC20({
  amount: depositAmount,
  productId: 0,
});

await publicClient.waitForTransactionReceipt({
  hash: mintTxHash,
});

Make a deposit

First, call approveAllowance to approve the deposit amount.

This is also an on-chain transaction with a confirmation hash.

const approveTxHash = await vertexClient.spot.approveAllowance({
  amount: depositAmount,
  productId: 0,
});

await publicClient.waitForTransactionReceipt({
  hash: approveTxHash,
});

Now we can deposit the tokens. This transaction is on-chain.

const depositTxHash = await vertexClient.spot.deposit({
  // Your choice of name for the subaccount, this subaccount will be credited with the deposit balance
  subaccountName: 'default',
  amount: depositAmount,
  productId: 0,
});

await publicClient.waitForTransactionReceipt({
  hash: depositTxHash,
});

Subaccounts

  • A subaccount is an independent trading account within Vertex, allowing traders to manage risk across independent subaccounts

  • Subaccounts are associated by a string name (max 12 char.) and the owner wallet address

After this, we inject a short delay while the offchain sequencer picks up the transaction and credits the account.

await new Promise((resolve) => setTimeout(resolve, 10000));

Query Subaccount balance

Now, call the getSubaccountEngineSummary function to retrieve an overview of your subaccount, including balances.

const subaccountData =
  await vertexClient.subaccount.getEngineSubaccountSummary({
    subaccountOwner: address,
    subaccountName,
  });
prettyPrintJson('Subaccount Data After Deposit', subaccountData);

Engine vs. Contract Queries

  • You may notice that there is a getSubaccountEngineSummary and getSubaccountSummary

  • The engine variants retrieve the state from the off-chain engine, while the contract variants retrieve the state from the on-chain contracts.

  • These should ultimately match up, given that our off-chain engine is fully synced and operational.

You should see that your balance associated with productId of 0 now reflects your deposit amount.

Full example

import { toFixedPoint } from '@vertex-protocol/utils';
import { getVertexClient, prettyPrintJson } from './common';

async function main() {
  const vertexClient = getVertexClient();
  const { walletClient, publicClient } = vertexClient.context;

  // If you have access to `walletClient`, you can call `walletClient.account.address`
  // directly instead of reaching into `vertexClient.context`
  const address = walletClient!.account.address;
  const subaccountName = 'default';
  // 10 USDC (6 decimals)
  const depositAmount = toFixedPoint(10, 6);

  // TESTNET ONLY - Mint yourself some tokens
  const mintTxHash = await vertexClient.spot._mintMockERC20({
    amount: depositAmount,
    productId: 0,
  });
  // Mint goes on-chain, so wait for confirmation
  await publicClient.waitForTransactionReceipt({
    hash: mintTxHash,
  });

  // Deposits require approval on the ERC20 token, this is on-chain as well
  const approveTxHash = await vertexClient.spot.approveAllowance({
    amount: depositAmount,
    productId: 0,
  });

  await publicClient.waitForTransactionReceipt({
    hash: approveTxHash,
  });

  // Now execute the deposit, which goes on-chain
  const depositTxHash = await vertexClient.spot.deposit({
    // Your choice of name for the subaccount, this subaccount will be credited with the deposit balance
    subaccountName: 'default',
    amount: depositAmount,
    productId: 0,
  });

  await publicClient.waitForTransactionReceipt({
    hash: depositTxHash,
  });
  
  await new Promise((resolve) => setTimeout(resolve, 10000));

  // For on-chain state, you can use `getSubaccountSummary` - these should match up
  const subaccountData =
    await vertexClient.subaccount.getEngineSubaccountSummary({
      subaccountOwner: address,
      subaccountName,
    });
  prettyPrintJson('Subaccount Data After Deposit', subaccountData);
}

main();
common functions