Skip to main content
Portal’s Flutter SDK provides token swapping functionality through the portal.trading.zeroX API. This integration allows you to retrieve swap quotes, inspect available liquidity sources, and execute token swaps using 0x.

Overview

Using the 0x integration, you can:
  • Fetch indicative prices for token swaps
  • Fetch swap quotes between supported tokens
  • Retrieve available liquidity sources
  • Execute swaps by signing and submitting transactions
All swap execution is performed by submitting the transaction data returned by 0x using portal.sendTransaction (or the lower-level portal.request).

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

Using a Custom 0x API Key (Optional)

By default, Portal uses the 0x API Key configured in 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 via the named zeroXApiKey parameter on any of the three methods.
If you’ve configured your 0x API key in the Portal Dashboard, you can omit the zeroXApiKey parameter:

Getting a Price (Indicative)

Use portal.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

Use portal.trading.zeroX.getQuote to fetch a swap quote from 0x with executable transaction data.

Getting Liquidity Sources

You can query available liquidity sources supported by 0x using portal.trading.zeroX.getSources.

Checking Quote Issues

When getting a quote, you may encounter issues related to allowances, balances, or simulation. Always check for these before executing a swap:

Executing the Swap

Once you receive a quote containing transaction data, execute the swap by submitting the transaction through the Portal SDK.
The transaction data returned by 0x may include gas parameters such as gas or gasPrice. 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.
The simplest path uses portal.sendTransaction, which forwards the call as eth_sendTransaction and returns the transaction hash:
If you need full control over the request envelope, you can use portal.request directly:

Error Handling

All three methods throw a PortalException when the native SDK or the 0x service returns an error. Catch it the same way you would any other Portal call:

Complete Swap Flow Example

Here’s a complete example of executing a token swap end-to-end:

Supported Networks

The portal.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 PortalException(ZEROX_GET_QUOTE_ERROR) from the native SDK.

Next Steps