LogoLogo
SupportGithubSign InGet Access
  • Introduction
  • GETTING STARTED
    • SDK Quick Start
    • API Quick Start
  • Guides
    • Web
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Web authentication methods
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Configure a custom subdomain
      • Eject a wallet
      • Using the EIP-1193 Provider
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • iOS
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Manage ERC20 tokens
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
          • Passkey + Enclave Storage
        • Recover a wallet
      • Troubleshooting Tips
      • Feature Flags
    • Android
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • React Native
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • Enclave MPC API
      • Create a client
      • Create a wallet
      • Send tokens
      • Sign Ethereum transactions
      • Sign Solana transactions
      • Sign Tron transactions
      • Sign Stellar Transaction
      • Concurrent Transactions
      • Back up a wallet
      • Eject a wallet
  • Reference
    • iOS
      • createWallet
      • backupWallet
      • recoverWallet
      • ejectPrivateKeys
      • registerBackupMethod
      • setGDriveConfiguration
      • setPasskeyConfiguration
      • setPasskeyAuthenticationAnchor
      • setPassword
      • availableRecoveryMethods
      • doesWalletExist
      • isWalletBackedUp
      • isWalletOnDevice
      • isWalletRecoverable
      • getBalances
      • getAssets
      • getNftAssets
      • getTransactions
      • sendSol
      • evaluateTransaction
      • buildEip155Transaction
      • buildSolanaTransaction
      • getWalletCapabilities
    • Android
      • Reference Documentation
    • React Native
      • @portal-hq/core
      • Storage adapters
        • Cloud storage
          • @portal-hq/gdrive-storage
          • @portal-hq/icloud-storage
        • Mobile storage
          • @portal-hq/keychain
          • @portal-hq/mobile-key-values
    • Enclave MPC API
      • V1 endpoints
    • Client API
      • V3 endpoints
      • V1 endpoints
    • Custodian API
      • V3 endpoints
      • V1 endpoints
    • Swaps API
      • V3 endpoints
      • V1 endpoints
  • Resources
    • Flutter
      • iOS
      • Android
    • Error codes
      • Overview
      • MPC errors
      • Network errors
      • General errors
      • Encryption errors
      • Portal Connect errors
    • Portal's MPC architecture
    • Authentication and API Keys
    • Self-Managed Backups
    • Alert Webhooks
    • Wallet lifecycle
    • Backup options
      • Password/PIN
      • GDrive
      • iCloud
      • Passkey + Enclave
    • WalletConnect metadata
    • Advanced security scanning
    • Account abstraction
    • Security firewall
    • Eject
    • Security
    • Blockchain support
    • Chain ID formatting
    • Testnet faucets
    • Going to Production
    • Rate Limits
    • Multi-backup migration guide
    • Multi-wallet migration guides
      • Migrating from Android SDK v3.x.x to v4.x.x
      • Migrating from iOS SDK v3.0.x to v3.2.x
  • Support
    • Changelog
      • Android
      • iOS
      • React Native
      • Web
      • Past Releases
        • 2024 Releases
        • 2023 Releases
    • Celo Hackathon Hub
    • Glossary
Powered by GitBook
On this page
  • Overview
  • Authentication
  • Supported Chains
  • Get a list of available liquidity sources
  • Get a quote for buying/selling tokens

Was this helpful?

  1. Reference
  2. Swaps API

V3 endpoints

Our Swaps API utilizes 0x to execute swaps on EVM chains.

Overview

The Swaps API can be accessed at https://api.portalhq.io/.

Authentication

There are two forms of required authentication in order to use the Swaps API

  • Client Authentication - a Client Session Token or Client API Key provided as a Bearer token in the Authentication header

  • 0x Authentication - a 0x API Key provided as apiKey property of the JSON request body

Supported Chains

  • Mainnet (eip155:1)

  • Optimism (eip155:10)

  • Binance Smart Chain (eip155:56)

  • Polygon (eip155:137)

  • Fantom (eip155:250)

  • Base (eip155:8453)

  • Arbitrum (eip155:42161)

  • Celo (eip155:42220)

  • Avalanche (eip155:43114)

  • Sepolia (eip155:11155111)

Get a list of available liquidity sources

POST /v3/swaps/sources

Returns a list of the available liquidity sources for a particular chain.

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <CLIENT_AUTHENTICATION_TOKEN>

Body Parameters

Name
Type
Description

address

string

The client's ETH wallet address

apiKey

string

Your 0x API Key

chainId

string

(e.g. "eip155:1" = Mainnet)

Example request

curl -X POST "https://api.portalhq.io/api/v3/swaps/sources" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer <CLIENT_AUTHENTICATION_TOKEN>" \
     -d '{
           "address": "<CLIENT_ETH_WALLET_ADDRESS>",
           "apiKey": "<YOUR_0x_API_KEY>",
           "chainId": "eip155:1"
         }'

Example response

The response of this request is a JSON object containing key/value pairs.

The key is the Token Symbol and the value is an acceptable value as the token property provided to the /quote route (either a Token Symbol or Token Address).

{
    "0x": "0x012345",
    "Aave_V2": "0x012345",
    "Balancer_V2": "0x012345",
    "BancorV3": "0x012345",
    ...
}

Get a quote for buying/selling tokens

POST /v3/swaps/quote

Get an easy-to-consume quote for buying or selling a token.

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <CLIENT_AUTHENTICATION_TOKEN>

Body Parameters

Name
Type
Description

address

string

The client's ETH wallet address.

apiKey

string (optional)

Your 0x API key.

chainId

string

(e.g. "eip155:1" = Mainnet)

buyToken

string

The token you'd like to buy.

buyAmount

number (optional)

The amount of buyToken you'd like to buy in WEI. Exactly one of either buyAmount or sellAmount must be provided.

sellToken

string

The token you'd like to sell.

sellAmount

number (optional)

The amount of sellToken you'd like to sell in WEI. Exactly one of either buyAmount or sellAmount must be provided.

Example request

curl -X POST "https://api.portalhq.io/api/v3/swaps/quote" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer <CLIENT_AUTHENTICATION_TOKEN>" \
     -d '{
           "address": "<CLIENT_ETH_WALLET_ADDRESS>",
           "apiKey": "<YOUR_0x_API_KEY>",
           "chainId": "eip155:1",
           "buyToken": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
           "sellToken": "ETH",
           "sellAmount": 1000000000000000000
         }'

Example response

{
  "allowanceTarget": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
  "cost": 10000000000,
  "transaction": {
    "data": "0xd9627aa...",
    "from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "gas": "111000",
    "to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
    "value": "0",
  }
}
PreviousSwaps APINextV1 endpoints

Last updated 17 days ago

Was this helpful?

The

The

CAIP-2 chainId
CAIP-2 chainId