Dolomite organizes each supported asset into its own market, giving users a clear way to supply, borrow, and manage positions across a range of tokens.Each market is built around a specific supported asset, making it easy to understand what users are interacting with when they deposit or withdraw. In this guide, USD1 is accessed through its Dolomite market.
Call withdrawWei on the Dolomite Deposit Router to pull USD1 back from the market to the user’s wallet. Pass the full wei amount to withdraw, or use a max value to exit entirely.
import {encodeFunctionData, parseUnits} from 'viem';import {useSendTransaction} from '@privy-io/react-auth';const {sendTransaction} = useSendTransaction();const depositRouterAbi = [ { type: 'function', name: 'withdrawWei', inputs: [ {name: '_isolationModeMarketId', type: 'uint256'}, {name: '_fromAccountNumber', type: 'uint256'}, {name: '_marketId', type: 'uint256'}, {name: '_amountWei', type: 'uint256'}, {name: '_balanceCheckFlag', type: 'uint8'} ], outputs: [], stateMutability: 'nonpayable' }] as const;const withdrawAmount = parseUnits('100', 18); // 100 USD1 (18 decimals)const data = encodeFunctionData({ abi: depositRouterAbi, functionName: 'withdrawWei', args: [ 0n, // _isolationModeMarketId: 0 for standard withdrawals ACCOUNT_NUMBER, // _fromAccountNumber: 0 for the default account USD1_MARKET_ID, // _marketId: Dolomite market ID for USD1 withdrawAmount, // _amountWei: amount of USD1 in wei 1 // _balanceCheckFlag: 1 (From) — validates sender balance post-withdrawal ]});const tx = await sendTransaction({ to: DOLOMITE_DEPOSIT_ROUTER as `0x${string}`, data, chainId: CHAIN_ID});
Always approve first: Your app must grant ERC-20 approval to the Dolomite Deposit Router before any deposit.
USD1 uses 18 decimals: Use parseUnits('100', 18) for amounts.
Market IDs identify assets: The _marketId parameter (1 for USD1 in this example) tells Dolomite which market to deposit into or withdraw from. Dolomite uses ascending numerical market IDs rather than token addresses to identify markets. Use _isolationModeMarketId = 0 for standard (non-isolated) assets.
Account number: Dolomite tracks balances per account number. Use 0 for the default account, or pass a custom value to support multiple sub-accounts per wallet.
Balance check flag: On withdrawal, _balanceCheckFlag = 1 checks that the sender’s balance remains non-negative after the operation. Use 0 to skip checks on both sides.
Supported chains: This guide uses Ethereum Mainnet. Dolomite is also deployed on Arbitrum — market IDs and router addresses differ per chain.
Privy makes it straightforward to build secure access to markets powered by Dolomite. For advanced use cases, refer to Dolomite, or reach out in Slack.
Your app is now ready to deposit USD1 into a Dolomite market using Privy embedded wallets!