getZapPositions and pass its address as srcToken. Pick EVM or Solana in any tab, and the rest of the page switches with it.
Setup
- EVM
- Solana
This example exits a Uniswap position on Base back into USDC, signing with
walletClient, a viem wallet client built from the private key in PRIVATE_KEY. No API key is needed.getZapChains lists the provider IDs each chain supports.Steps
- EVM
- Solana
1
Find the position
getZapPositions lists your open positions with one provider on one chain. Each has its address, amount and value in amountUSD. Uniswap positions are NFTs, so they also carry nftDetails: the NFT’s id and its manager contract.2
Quote
getZapQuote returns the exit route and what you’ll get back. srcToken is the position’s address and positionDetails.nftId names the NFT; with no amount, the whole position exits. For a partial exit, set amount to part of position.amount. destToken doesn’t have to be USDC: other tokens and native ETH work when DZap has a route, and setting destChainId to another chain bridges the result there.3
Approve
The zap contract, the quote’s
approvalData[0].approveTo, needs permission to move the position NFT. approve() handles NFTs too: pass the NFT’s manager as the token and its id as the amount.Exiting an ERC-20 position, such as a vault share or a Curve LP token? Leave out
positionDetails, set amount, and approve the token with getAllowance and approve() as on the deposit page.4
Build & send
buildZapTxn builds the exit and checks it against your wallet, so it throws if it would fail. zap() then signs and sends it: one transaction exits the position and swaps what comes out into USDC for recipient.5
Status
Poll
getZapTxnStatus with the transaction hash until the status leaves PENDING; COMPLETED means every step finished, and status.steps reports each one. DZap answers 404 until it sees the transaction, and 429 once its rate limit is used up, so the catch skips only those two and rethrows anything else. The loop gives up after 5 minutes (raise it if the route bridges), and the check after it throws unless the status is COMPLETED.End-to-end
- EVM
- Solana
API usage
The same flow over REST, on the zap API athttps://zap.dzap.io/v1. Each response wraps its result in data.
- EVM
- Solana
What can go wrong
NFT id not found: the position is an NFT and the request has nopositionDetails.nftId.Amount not foundorToken amount not found: the position is a token and the request has noamount.No valid quote found: DZap has no route from the position to thatdestToken. Pick another token.buildZapTxnthrowsExecution reverted: the build checks the exit against your wallet, so the position’s approval must be confirmed first. The error response’smessagehas the revert reason.positionsis empty: the wallet has no open position with that provider on that chain.getZapChainslists the provider IDs each chain supports.currently withdrawable from this market: the lending market doesn’t have that much free liquidity right now. Exit part of the position now and the rest later.- Several Solana transactions: some Solana routes return two or more transactions with
isJitoTx: true, which have to land together as a Jito bundle. The SDK can’t submit bundles yet, so the code here covers single-transaction routes like Jupiter Lend. Blockhash not foundorComputationalBudgetExceededon Solana: the transaction expired before you sent it, or needed more compute than the build allowed. Build and sign again right away.Not completed: no status: DZap never returned a status, usually because the transaction failed on-chain. On Solana, query by the signature; the build’stxnIdreturnsFailed to process transaction.- HTTP 429: the zap API allows 60 requests a minute.