portal.trading.zeroX.tradeAsset(...) and lower-level access through
portal.trading.zeroX.
Overview
Using the 0x integration, you can:- Trade assets end-to-end with one high-level call
- Track lifecycle progress from quote fetch to confirmation
- Override signer and confirmation behavior per call when needed
- Fetch indicative prices for token swaps
- Fetch swap quotes between supported tokens
- Retrieve available liquidity sources
- Execute swaps manually by signing and submitting transactions from a quote
Prerequisites
Before using the 0x API, make sure you have:- A properly initialized Portal client
- An active wallet with sufficient balance on the source network
(see Create a wallet) - 0x integration enabled in your Portal Dashboard (see 0x Integration) OR have a 0x API Key available
High-Level Methods
tradeAsset
Fetches a 0x quote, signs and broadcasts the quote transaction, waits for on-chain confirmation, and returns hashes.
Signature
ZeroXTradeAssetOptions:
Return value
0x
tradeAsset execution precedence:- Signer: per-call
options.signAndSendTransaction→ instance default signer → throw - Confirmation: per-call
options.waitForConfirmation→ instance default waiter, or on Web,evmRequestFn+ receipt polling whenwaitForConfirmationis omitted
false, times out, throws an error, or the network is unsupported, the swap fails immediately and throws.On portal-react-native, tradeAsset does not offer evmRequestFn; you supply waitForConfirmation (or rely on the Portal default where wired).onProgress + default on-chain wait)
try/catch around tradeAsset; onProgress may emit failed before the thrown error.
Example (custom API key + execution options)
Low-level methods
The following methods return quotes, prices, or raw transaction data for you to sign withportal.request when you need full control over each step.
Using a Custom 0x API Key (Optional)
By default, Portal uses the 0x API Key that can be added through the Portal Dashboard to communicate with the 0x integration. If you have a 0x API key that you want to test with locally, you can optionally include it in the request body via the options parameter.Getting a Price (Indicative)
Useportal.trading.zeroX.getPrice to retrieve an indicative price for a
token swap without generating executable transaction data.
This method is useful for displaying prices, estimating swap outcomes, or
building preview experiences without committing to a quote.
Getting a Swap Quote
Useportal.trading.zeroX.getQuote to fetch a swap quote from 0x.
Getting Liquidity Sources
You can query available liquidity sources supported by 0x usingportal.trading.zeroX.getSources.
For full request and response details, refer to the Client API documentation.
Low-level: Executing the Swap
Once you receive a quote containing transaction data, execute the swap by sending the transaction throughportal.request.
Note
The transaction data returned by 0x may include gas parameters such asgasorgasPrice. These fields are optional — you can omit them and let Portal estimate gas automatically, or include them if you prefer to use 0x’s suggested values.
Supported Networks
Theportal.trading.zeroX API supports a predefined set of EIP-155 networks.
Requests using unsupported chains will fail.
0x supports mainnet networks only — calls against testnets surface as a
ZEROX_GET_QUOTE_ERROR from the SDK.Next Steps
- Learn how to sign Ethereum transactions
- Explore how to send tokens
- Review the Client API 0x endpoints