API
This section will walk you through the required steps to get quote and submit a swap using Mosaic Aggregator.
Swagger
Find the best quote to swap with Mosaic Aggregator
0x1::aptos_coin::AptosCoin0x275f508689de8756169d1ee02d889c777de1cebda3a7bbcce63ba8a27c563c6f::tokens::USDCAmount of the token to be swapped
100000000Whether the fee is in the source asset
trueFee in basis points
30Fee receiver address
0x0145f3f2a68d9bcf8f5a1ae2ca34760c76a9742c7b22b36a54f706dd587cc26cSlippage tolerance in basis points
10Sender address
0x0145f3f2a68d9bcf8f5a1ae2ca34760c76a9742c7b22b36a54f706dd587cc26cReceiver address. If not provided, the sender address will be used.
0x0145f3f2a68d9bcf8f5a1ae2ca34760c76a9742c7b22b36a54f706dd587cc26cSuccessfully found quote
Successfully found quote
Retrieve tokens based on IDs, cursor, count, and pattern
List of token IDs to retrieve. If omit, all tokens will be retrieved.
Cursor for pagination.
Number of tokens to retrieve.
Pattern to match token names.
A list of tokens and the next cursor for pagination.
A list of tokens and the next cursor for pagination.
Setup Authentication
Get quote
To retrieve the best swap rate, send the following HTTP request to get a quote:
This will return the best available quote for swapping the source asset (AptosCoin) into the destination asset (USDC) based on current market conditions.
Here is a detailed guide using Typescript:
1. Setup Environment
Import the required libraries and initialize your connection to the Aptos testnet using the AptosConfig and Aptos objects from the @aptos-labs/ts-sdk. This sets up your environment for making requests to the Mosaic Aggregator API and interacting with Aptos.
2. Setup User Account
Here, you will create an Aptos account using the user's private key. You need to fill in your own private key when initializing the account.
3. Define Assets and Amount
Specify the assets to swap and the amount (in APTOS decimals):
4. Get a Quote from Mosaic Aggregator API
Retrieve the best swap rate by making a GET request to the Mosaic API.
5. Build the transaction
Once you have the quote, you use the returned data (function, type arguments, and function arguments) to build a transaction that will perform the swap.
6. Sign and submit the transaction
After building the transaction, you sign it using the user's private key and submit the transaction to the Aptos blockchain. The transaction hash will be logged, which can be used to check the transaction status on the explorer.
By following this guide, you will be able to integrate the Mosaic Aggregator API for performing token swaps on the Aptos network. For further assistance or inquiries, feel free to reach out to the Mosaic support team on Discord or Telegram. \
Last updated