Guide
An overview guide on how to integrate OpenOcean Swap API
OpenOcean Swap API Integration Guide
In the following guide, it will introduce how to use this OpenOcean's swap API in the most efficient way.
Swap Overview
The swap function enables users to seamlessly exchange one asset/token for another directly at the best swap rate. The swap API supports for 30+ on EVM and Non-EVM chains, refer the docs of supported chains to check in details.
Swap Tokens in 7 Steps
(Optional) Get token info
Get gasPrice
(Optional) Set a token allowance
Set token approvals and signature
Price quote
Get transaction body
Send transaction and signature
1. Get Token Info
You can use the get Token List API to to retrieve all available tokens on the selected blockchain. Next, select input token from the chain to swap. Make sure to save the token information for further use.
Example request
Example response
2. Get gasPrice
Example request
Example response
3. (Optional) Set a Token Allowance
Before proceeding with the swap, you'll need to set a token allowance. This process is to grant a third party to allow access your tokens on your behalf. In this case, you'll need to specify the amount of tokens, and approve for the swap contract to trade your ERC20 tokens.
Example request
Example response
4. Token Approve
Approving assets is necessary for Defi users to grant the contract to use their tokens to swap. As with the getBalance method, you can use the wallet method or directly use our SDK to get a specific token approved for trading. You can use the getAllowance API to query the allowance data from our server.
Example:
5. Price Quote
In this API, you are able to fetch the price quote for selected token pairs. In the following, we used token pair of OOE/BNB on BNB chain as an example.
Example request
Example response:
6. Get Transaction Body
You can use swap quote API to get transaction calldata, then submit the transaction on-chain using your wallet.
Example request
Example response
7. Send transaction
Once your wallet plugin is triggered, it confirms that the sendTransaction function has been successfully called with all parameters set. When our swap gets processed and executed on chain, the transaction hash will be generated.
Example request
Last updated
