### Install Mayan Swap SDK
Source: https://docs.mayan.finance/link/swap
Install the SDK using npm. This is the first step to using the cross-chain swap functionality.
```bash
npm install --save @mayanfinance/swap-sdk
```
--------------------------------
### Referrer Addresses Example
Source: https://docs.mayan.finance/link/swap
An example structure for the optional referrerAddresses object, specifying wallet addresses for different network types.
```javascript
{
evm: "YOUR EVM WALLET",
solana: "YOUR SOLANA WALLET",
sui: "YOUR SUI WALLET"
}
```
--------------------------------
### Get Supported Chains Configuration
Source: https://docs.mayan.finance/integration/quote-api
This endpoint returns configuration details for all supported chains, indicating whether each can be used as an origin or destination chain. The response includes chain names, IDs, and other relevant attributes.
```powershell
curl -X 'GET' \
'https://sia.mayan.finance/v10/init' \
-H 'accept: application/json'
```
--------------------------------
### Get Supported Chains Configuration
Source: https://docs.mayan.finance/integration/quote-api
Retrieves the configuration for all supported chains, indicating their availability as origin or destination chains.
```APIDOC
## GET /v10/init
### Description
Returns configuration for every supported chain, including whether it can be used as an origin or destination chain.
### Method
GET
### Endpoint
`/v10/init`
### Response
#### Success Response (200)
- **chains** (array) - A list of chain objects, each containing chain details, `originActive` (boolean), and `destinationActive` (boolean).
### Request Example
```bash
curl -X 'GET' \
'https://sia.mayan.finance/v10/init' \
-H 'accept: application/json'
```
This endpoint provides a JSON response containing a comprehensive list of all chains supported by the platform. Each chain entry includes detailed metadata such as the chain's name, chain ID, and other relevant attributes.
Two key fields indicate the chain's functionality within the platform:
* `originActive`: Specifies whether the chain is supported as a source chain.
* `destinationActive`: Specifies whether the chain is supported as a destination chain.
Use this endpoint to determine compatibility and availability of specific chains for your operations.
```
--------------------------------
### Get Supported Tokens by Chain
Source: https://docs.mayan.finance/integration/quote-api
Use this endpoint to retrieve a list of supported tokens for a specific chain. Remove the 'chain' query parameter to get an aggregated list from all chains.
```powershell
curl -X 'GET' \
'https://price-api.mayan.finance/v3/tokens?chain=solana' \
-H 'accept: application/json'
```
--------------------------------
### Get Supported Tokens
Source: https://docs.mayan.finance/integration/quote-api
Retrieves a list of supported tokens from a specific chain or all chains. This is useful for understanding which tokens can be used for transactions.
```APIDOC
## GET /v3/tokens
### Description
Retrieves a list of supported tokens. You can filter by a specific chain or omit the `chain` parameter to get tokens from all chains.
### Method
GET
### Endpoint
`/v3/tokens`
### Query Parameters
- **chain** (string) - Optional - The name of the chain to filter tokens by (e.g., 'solana').
### Response
#### Success Response (200)
- **tokens** (array) - A list of token objects, each containing details like symbol, address, decimals, and logo URI.
### Request Example
```bash
curl -X 'GET' \
'https://price-api.mayan.finance/v3/tokens?chain=solana' \
-H 'accept: application/json'
```
```
--------------------------------
### Get Swap Quote
Source: https://docs.mayan.finance/integration/quote-api
This endpoint retrieves the best route and swap rate for a given token pair and amount. It requires details about the input and output tokens, chains, slippage tolerance, and other optional parameters for optimizing the swap.
```APIDOC
## GET /v3/quote
### Description
Retrieves the best route and swap rate for a given token pair and amount.
### Method
GET
### Endpoint
/v3/quote
### Parameters
#### Query Parameters
- **amountIn** (string) - Required - The amount of the input token.
- **fromToken** (string) - Required - The contract address of the input token.
- **fromChain** (string) - Required - The chain ID or name of the input token.
- **toToken** (string) - Required - The contract address of the output token.
- **toChain** (string) - Required - The chain ID or name of the output token.
- **slippageBps** (string) - Required - The slippage tolerance in basis points (e.g., 300 for 3%).
- **gasDrop** (string) - Optional - Specifies gas drop settings.
- **swift** (string) - Optional - Enables swift mode.
- **mctp** (string) - Optional - Enables MCTP.
- **fastMctp** (string) - Optional - Enables fast MCTP.
- **wormhole** (string) - Optional - Enables Wormhole integration.
- **solanaProgram** (string) - Optional - The Solana program ID for swaps.
- **forwarderAddress** (string) - Optional - The address of the forwarder contract.
- **sdkVersion** (string) - Optional - The version of the SDK being used.
### Request Example
```powershell
curl -X 'GET' 'https://price-api.mayan.finance/v3/quote?amountIn=100&fromToken=0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e&fromChain=avalanche&toToken=0x0000000000000000000000000000000000000000&toChain=solana&slippageBps=300&gasDrop=0&swift=true&mctp=true&fastMctp=true&wormhole=true&solanaProgram=FC4eXxkyrMPTjiYUpp4EAnkmwMbQyZ6NDCh1kfLn6vsf&forwarderAddress=0x337685fdaB40D39bd02028545a4FfA7D287cC3E2&sdkVersion=13_1_0'
```
### Response
#### Success Response (200)
- **quote** (object) - Contains details about the swap quote, including routes, rates, and estimated fees.
- **routes** (array) - A list of possible swap routes.
- **bestRoute** (object) - The recommended swap route.
- **estimatedGas** (object) - Estimated gas costs for the swap.
#### Response Example
{
"quote": {
"routes": [
{
"id": "route-1",
"rate": "0.995",
"estimatedGas": {
"amount": "0.001",
"token": "AVAX"
}
}
],
"bestRoute": {
"id": "route-1",
"rate": "0.995",
"estimatedGas": {
"amount": "0.001",
"token": "AVAX"
}
},
"estimatedGas": {
"amount": "0.001",
"token": "AVAX"
}
}
}
```
--------------------------------
### Quote API Response Example
Source: https://docs.mayan.finance/integration/quote-api
This JSON object represents a typical response from the Quote API. It includes details for a single quote, which is the fastest and best-return option by default. The response contains information about the quote's meta-data, costs, token details for both input and output, and chain information.
```json
{
"quotes": [
{
"meta": {
"advertisedDescription": "Cheapest and Fastest",
"advertisedTitle": "Best",
"icon": "https://cdn.mayan.finance/fast_icon.png",
"switchText": "Switch to the best route",
"title": "Best"
},
"sendTransactionCost": 0,
"gasless": false,
"slippageBps": 300,
"effectiveAmountIn": 100,
"effectiveAmountIn64": "100000000",
"expectedAmountOut": 1.201839546,
"price": 0.01201963167985677,
"minAmountOut": 1.16578436,
"minReceived": 1.16578436,
"solanaRelayerFee": null,
"solanaRelayerFee64": null,
"redeemRelayerFee": null,
"redeemRelayerFee64": null,
"refundRelayerFee": null,
"refundRelayerFee64": "711",
"cancelRelayerFee64": "9147",
"submitRelayerFee64": "0",
"clientRelayerFeeSuccess": null,
"clientRelayerFeeRefund": 0.00902389942474755,
"deadline64": "1774621897",
"fromToken": {
"name": "USD Coin",
"symbol": "USDC",
"mint": "FHfba3ov5P3RjaiLVgh8FTv4oirxQDoVXuoUUDvHuXax",
"contract": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
"chainId": 43114,
"wChainId": 6,
"decimals": 6,
"logoURI": "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png?1547042389",
"coingeckoId": "usd-coin",
"realOriginContractAddress": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
"realOriginChainId": 6,
"supportsPermit": true
},
"fromChain": "avalanche",
"toToken": {
"name": "SOL",
"symbol": "SOL",
"mint": "So11111111111111111111111111111111111111112",
"contract": "0x0000000000000000000000000000000000000000",
"chainId": 0,
"wChainId": 1,
"decimals": 9,
"logoURI": "https://statics.mayan.finance/SOL.png",
"wrappedAddress": "So11111111111111111111111111111111111111112",
"coingeckoId": "solana",
"realOriginContractAddress": "So11111111111111111111111111111111111111112",
"realOriginChainId": 1,
"supportsPermit": false
},
"toChain": "solana",
"gasDrop": 0,
"eta": 1,
"etaSeconds": 3,
"clientEta": "3s",
"bridgeFee": 0,
"suggestedPriorityFee": 0,
"type": "SWIFT",
"priceStat": {
"ratio": 0.9996,
"status": "GOOD"
},
"referrerBps": 0,
"protocolBps": 3,
"onlyBridging": false,
"minMiddleAmount": 100,
"sourceSwapExpense": 0,
"swiftVersion": "V2",
"swiftMayanContract": "0x40fFE85A28DC9993541449464d7529a922142960",
"swiftAuctionMode": 2
}
],
"minimumSdkVersion": [
7,
0,
0
]
}
```
--------------------------------
### Get Swap Quote Request
Source: https://docs.mayan.finance/integration/quote-api
Use this cURL command to request a quote for swapping tokens. Specify the amount, token addresses, chains, slippage tolerance, and other parameters for optimal routing.
```powershell
curl -X 'GET' 'https://price-api.mayan.finance/v3/quote?amountIn=100&fromToken=0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e&fromChain=avalanche&toToken=0x0000000000000000000000000000000000000000&toChain=solana&slippageBps=300&gasDrop=0&swift=true&mctp=true&fastMctp=true&wormhole=true&solanaProgram=FC4eXxkyrMPTjiYUpp4EAnkmwMbQyZ6NDCh1kfLn6vsf&forwarderAddress=0x337685fdaB40D39bd02028545a4FfA7D287cC3E2&sdkVersion=13_1_0'
```
--------------------------------
### Get Quotes
Source: https://docs.mayan.finance/integration/quote-api
Retrieves a list of quotes for a cryptocurrency exchange. By default, it returns the fastest and best-return options. Set `fullList` to `true` to get all available quotes.
```APIDOC
## GET /quotes
### Description
Retrieves a list of quotes for a cryptocurrency exchange. By default, it returns the fastest and best-return options. Set `fullList` to `true` to get all available quotes.
### Query Parameters
- **fullList** (boolean) - Optional - If true, returns all available quote options. Otherwise, returns at most two quotes (fastest and best-return).
### Response
#### Success Response (200)
- **quotes** (array) - An array of quote objects, each containing details about a potential exchange route.
- **minimumSdkVersion** (array) - The minimum required version of the SDK.
### Response Example
```json
{
"quotes": [
{
"meta": {
"advertisedDescription": "Cheapest and Fastest",
"advertisedTitle": "Best",
"icon": "https://cdn.mayan.finance/fast_icon.png",
"switchText": "Switch to the best route",
"title": "Best"
},
"sendTransactionCost": 0,
"gasless": false,
"slippageBps": 300,
"effectiveAmountIn": 100,
"effectiveAmountIn64": "100000000",
"expectedAmountOut": 1.201839546,
"price": 0.01201963167985677,
"minAmountOut": 1.16578436,
"minReceived": 1.16578436,
"solanaRelayerFee": null,
"solanaRelayerFee64": null,
"redeemRelayerFee": null,
"redeemRelayerFee64": null,
"refundRelayerFee": null,
"refundRelayerFee64": "711",
"cancelRelayerFee64": "9147",
"submitRelayerFee64": "0",
"clientRelayerFeeSuccess": null,
"clientRelayerFeeRefund": 0.00902389942474755,
"deadline64": "1774621897",
"fromToken": {
"name": "USD Coin",
"symbol": "USDC",
"mint": "FHfba3ov5P3RjaiLVgh8FTv4oirxQDoVXuoUUDvHuXax",
"contract": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
"chainId": 43114,
"wChainId": 6,
"decimals": 6,
"logoURI": "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png?1547042389",
"coingeckoId": "usd-coin",
"realOriginContractAddress": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
"realOriginChainId": 6,
"supportsPermit": true
},
"fromChain": "avalanche",
"toToken": {
"name": "SOL",
"symbol": "SOL",
"mint": "So11111111111111111111111111111111111111112",
"contract": "0x0000000000000000000000000000000000000000",
"chainId": 0,
"wChainId": 1,
"decimals": 9,
"logoURI": "https://statics.mayan.finance/SOL.png",
"wrappedAddress": "So11111111111111111111111111111111111111112",
"coingeckoId": "solana",
"realOriginContractAddress": "So11111111111111111111111111111111111111112",
"realOriginChainId": 1,
"supportsPermit": false
},
"toChain": "solana",
"gasDrop": 0,
"eta": 1,
"etaSeconds": 3,
"clientEta": "3s",
"bridgeFee": 0,
"suggestedPriorityFee": 0,
"type": "SWIFT",
"priceStat": {
"ratio": 0.9996,
"status": "GOOD"
},
"referrerBps": 0,
"protocolBps": 3,
"onlyBridging": false,
"minMiddleAmount": 100,
"sourceSwapExpense": 0,
"swiftVersion": "V2",
"swiftMayanContract": "0x40fFE85A28DC9993541449464d7529a922142960",
"swiftAuctionMode": 2
}
],
"minimumSdkVersion": [
7,
0,
0
]
}
```
```
--------------------------------
### Get Quote
Source: https://docs.mayan.finance/integration/quote-api
Retrieves a quote for a token swap based on the provided parameters. Users must specify either `amountIn` or `amountIn64`, and either `slippageBps` or `slippage`.
```APIDOC
## GET /quote
### Description
Retrieves a quote for a token swap.
### Method
GET
### Endpoint
/quote
### Parameters
#### Query Parameters
- **amountIn** (Number) - Required* - Input amount in human-readable format (e.g. `100` for 100 USDC). Either `amountIn` or `amountIn64` must be provided.
- **amountIn64** (String) - Required* - Input amount in base units (smallest denomination, e.g. `100000000` for 100 USDC). Either `amountIn` or `amountIn64` must be provided.
- **fromToken** (String) - Required - Token address on the source chain (use `0x0000000000000000000000000000000000000000` for native tokens)
- **fromChain** (String) - Required - Source chain name (e.g. `solana`, `ethereum`, `bsc`, `avalanche`, `arbitrum`, `base`, `optimism`, `polygon`, `sui`)
- **toToken** (String) - Required - Token address on the destination chain
- **toChain** (String) - Required - Destination chain name
- **slippageBps** (Number) - Required* - Maximum slippage in basis points (e.g. `300` = 3%, max `500`). Either `slippageBps` or `slippage` must be provided.
- **slippage** (Number) - Required* - Maximum slippage as a decimal (e.g. `0.03` = 3%). Either `slippageBps` or `slippage` must be provided.
- **swift** (Boolean) - Optional - Enable [Swift](/architecture/swift) routes
- **mctp** (Boolean) - Optional - Enable [MCTP](/architecture/mctp) routes
- **fastMctp** (Boolean) - Optional - Enable Fast MCTP routes
- **wormhole** (Boolean) - Optional - Enable [Wormhole Swap](/architecture/wh-swap) routes
- **gasless** (Boolean) - Optional - Enable gasless swap mode
- **solanaProgram** (String) - Optional - Mayan Solana program address
- **forwarderAddress** (String) - Optional - Mayan Forwarder contract address
- **sdkVersion** (String) - Optional - SDK version in `major_minor_patch` format (e.g. `13_1_0`)
- **referrer** (String) - Optional - Referrer Solana address that receives the referrer fee
- **referrerBps** (Number) - Optional - Basis points the integrator earns through the referral program. Default is 0.
- **gasDrop** (Number) - Optional - Amount of native gas to deliver to the user on the destination chain. Default is 0.
- **fullList** (Boolean) - Optional - Enables returning all available quote options instead of the default limited (fastest and best-return) results. Default is `false`.
- **destinationAddress** (String) - Optional - Helps provide a more accurate quote, for example by checking whether the Solana ATA exists.
- **apiKey** (String) - Optional - Defines an API key that prevents the **rate-limit-exceeded** error on a per-IP basis.
### Response
#### Success Response (200)
- **quote** (Object) - Contains quote details.
- **id** (String) - Unique identifier for the quote.
- **fromAmount** (String) - The amount of the source token to be swapped.
- **toAmount** (String) - The estimated amount of the destination token to be received.
- **toAmountMin** (String) - The minimum amount of the destination token to be received, considering slippage.
- **expectedAmountOut** (String) - The expected amount of the destination token to be received.
- **protocol** (String) - The protocol used for the swap.
- **path** (Array) - The path of the swap, detailing intermediate steps if any.
- **estimatedGas** (Object) - Estimated gas fees for the transaction.
- **fromAmount** (String) - Gas fee in the source token.
- **toAmount** (String) - Gas fee in the destination token.
- **price** (String) - The exchange rate between the source and destination tokens.
- **priceImpact** (String) - The impact of this trade on the market price.
- **fee** (Object) - Fee details for the swap.
- **amount** (String) - The total fee amount.
- **token** (String) - The token in which the fee is paid.
- **bps** (Number) - The fee in basis points.
- **route** (String) - Identifier for the route taken.
- **duration** (Number) - Estimated duration of the swap in seconds.
- **providerFee** (Object) - Provider-specific fee details.
- **amount** (String) - The amount of the provider fee.
- **token** (String) - The token in which the provider fee is paid.
- **bps** (Number) - The provider fee in basis points.
- **networkFee** (Object) - Network fee details.
- **amount** (String) - The amount of the network fee.
- **token** (String) - The token in which the network fee is paid.
- **bps** (Number) - The network fee in basis points.
- **integratorFee** (Object) - Integrator fee details.
- **amount** (String) - The amount of the integrator fee.
- **token** (String) - The token in which the integrator fee is paid.
- **bps** (Number) - The integrator fee in basis points.
- **referrerFee** (Object) - Referrer fee details.
- **amount** (String) - The amount of the referrer fee.
- **token** (String) - The token in which the referrer fee is paid.
- **bps** (Number) - The referrer fee in basis points.
- **gasDrop** (Object) - Details about the gas drop.
- **amount** (String) - The amount of gas dropped.
- **token** (String) - The token used for the gas drop.
- **recipient** (String) - The address receiving the swapped tokens.
- **uuid** (String) - Unique identifier for the swap transaction.
- **sourceToken** (Object) - Details of the source token.
- **address** (String) - Token address.
- **symbol** (String) - Token symbol.
- **decimals** (Number) - Token decimals.
- **destinationToken** (Object) - Details of the destination token.
- **address** (String) - Token address.
- **symbol** (String) - Token symbol.
- **decimals** (Number) - Token decimals.
- **chain** (Object) - Details of the chain.
- **from** (String) - Source chain name.
- **to** (String) - Destination chain name.
- **type** (String) - Type of swap route (e.g., `SWAP`, `TRANSFER`).
- **isFast** (Boolean) - Indicates if the route is considered fast.
- **isGuaranteed** (Boolean) - Indicates if the route is guaranteed.
- **isStable** (Boolean) - Indicates if the route is stable.
- **isSwift** (Boolean) - Indicates if the route uses Swift.
- **isMCTP** (Boolean) - Indicates if the route uses MCTP.
- **isFastMCTP** (Boolean) - Indicates if the route uses Fast MCTP.
- **isWormhole** (Boolean) - Indicates if the route uses Wormhole.
- **isGasless** (Boolean) - Indicates if the route is gasless.
- **solanaProgram** (String) - Mayan Solana program address for the route.
- **forwarderAddress** (String) - Mayan Forwarder contract address for the route.
- **sdkVersion** (String) - SDK version used for this quote.
- **referrer** (String) - Referrer address associated with this quote.
- **referrerBps** (Number) - Basis points for the referrer fee.
- **gasDrop** (Number) - Gas drop amount for this quote.
- **fullList** (Boolean) - Indicates if all available quote options were returned.
- **destinationAddress** (String) - Destination address for the swap.
- **apiKey** (String) - API key used for this quote.
#### Response Example
```json
{
"quote": {
"id": "q_abc123",
"fromAmount": "100000000",
"toAmount": "99500000",
"toAmountMin": "99000000",
"expectedAmountOut": "99500000",
"protocol": "mayan",
"path": ["USDC", "SOL"],
"estimatedGas": {
"fromAmount": "10000",
"toAmount": "0.05"
},
"price": "0.995",
"priceImpact": "0.01",
"fee": {
"amount": "50000",
"token": "USDC",
"bps": 50
},
"route": "direct",
"duration": 30,
"providerFee": {
"amount": "10000",
"token": "USDC",
"bps": 10
},
"networkFee": {
"amount": "5000",
"token": "USDC",
"bps": 5
},
"integratorFee": {
"amount": "5000",
"token": "USDC",
"bps": 5
},
"referrerFee": {
"amount": "2000",
"token": "USDC",
"bps": 2
},
"gasDrop": {
"amount": "0.01",
"token": "SOL"
},
"recipient": "recipient_address",
"uuid": "uuid_abc123",
"sourceToken": {
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606e484",
"symbol": "USDC",
"decimals": 6
},
"destinationToken": {
"address": "0x9001000000000000000000000000000000000000",
"symbol": "SOL",
"decimals": 9
},
"chain": {
"from": "ethereum",
"to": "solana"
},
"type": "SWAP",
"isFast": true,
"isGuaranteed": true,
"isStable": true,
"isSwift": false,
"isMCTP": false,
"isFastMCTP": false,
"isWormhole": false,
"isGasless": false,
"solanaProgram": null,
"forwarderAddress": null,
"sdkVersion": "13.1.0",
"referrer": "referrer_address",
"referrerBps": 20,
"gasDrop": 0,
"fullList": false,
"destinationAddress": "destination_address",
"apiKey": "your_api_key"
}
}
```
```
--------------------------------
### Getting a Quote
Source: https://docs.mayan.finance/link/swap
Fetches a quote for a cross-chain swap. This function requires details about the tokens, chains, and slippage preferences. Optional parameters include gasDrop for destination chain gas, referrer information, and an API key for higher rate limits.
```APIDOC
## Getting Quote:
```javascript
const quotes = await fetchQuote({
amountIn64: "250000000", // if fromToken is USDC means 250 USDC
fromToken: fromToken.contract,
toToken: toToken.contract,
fromChain: "avalanche",
toChain: "solana",
slippageBps: "auto", // or a number like 300 for 3%
gasDrop: 0.04, // optional
referrer: "YOUR SOLANA WALLET ADDRESS", // optional
referrerBps: 5, // optional
apiKey: "YOUR API KEY", // optional
});
```
### Parameters:
- **amountIn64** (string) - Required - The amount of tokens to swap, represented as a 64-bit integer string.
- **fromToken** (string) - Required - The contract address of the token to swap from.
- **toToken** (string) - Required - The contract address of the token to swap to.
- **fromChain** (string) - Required - The source chain identifier.
- **toChain** (string) - Required - The destination chain identifier.
- **slippageBps** (string | number) - Required - The slippage tolerance in basis points (e.g., 300 for 3%) or "auto" for automatic slippage.
- **gasDrop** (number) - Optional - The amount of native token to receive on the destination chain as gas.
- **referrer** (string) - Optional - The wallet address to receive referrer fees.
- **referrerBps** (number) - Optional - The basis points for the referrer fee.
- **apiKey** (string) - Optional - An API key for increased rate limits.
```
--------------------------------
### Prepare Referrer Addresses for SDK
Source: https://docs.mayan.finance/integration/referral
Define a mapping of referrer wallet addresses for each virtual machine (VM) type before integrating with the SDK. Ensure you use valid addresses for Solana, EVM, and Sui.
```javascript
const referrerAddresses = {
solana: 'VALID_SOLANA_WALLET_ADDRESS',
evm: 'VALID_EVM_WALLET_ADDRESS',
sui: 'VALID_SUI_WALLET_ADDRESS'
};
```
--------------------------------
### Initialize Mayan Swap Widget
Source: https://docs.mayan.finance/integration/swap-widget
Include this script to load the Mayan widget and initialize it with custom configurations. Ensure the container element ID matches.
```javascript
```
--------------------------------
### swapAndForwardEth
Source: https://docs.mayan.finance/integration/forwarder-contract
Performs a swap on the source chain before bridging the native token.
```APIDOC
## swapAndForwardEth
### Description
Performs a swap on the source chain using the input native token and then bridges the resulting middle token. This function is suitable for scenarios where you need to swap the native currency for another token before bridging.
### Method
This is a contract function call, not an HTTP method.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **amountIn** (uint256) - Required - Input amount of the native token.
- **swapProtocol** (address) - Required - Contract address of the swap protocol.
- **swapData** (bytes) - Required - Data needed by the swap protocol.
- **middleToken** (address) - Required - The output token address from the swap protocol.
- **minMiddleAmount** (uint256) - Required - Minimum output amount of the swap step; the transaction will revert if this amount is not met.
- **mayanProtocol** (address) - Required - Address of the Mayan final contract.
- **mayanData** (bytes) - Required - Bytes data for the Mayan final contract.
### Request Example
```json
{
"amountIn": "1000000000000000000",
"swapProtocol": "0x...",
"swapData": "0x...",
"middleToken": "0x...",
"minMiddleAmount": "900000000000000000",
"mayanProtocol": "0x...",
"mayanData": "0x..."
}
```
### Response
#### Success Response (200)
This function is a contract call and does not return a standard HTTP response. Success is indicated by the transaction being mined without reverting.
#### Response Example
None (contract call)
```
--------------------------------
### forwardERC20
Source: https://docs.mayan.finance/integration/forwarder-contract
Initiates a swap using an ERC20 token as input. Requires prior approval or a permit object.
```APIDOC
## forwardERC20
### Description
Forwards an ERC20 token from the source chain. This function assumes the input token is an ERC20.
### Method
This is a contract function call, not an HTTP method.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **tokenIn** (address) - Required - Input token address.
- **amountIn** (uint256) - Required - Input amount.
- **permitParams** (PermitParams) - Required - Signed permission (eip-2612). Pass zero for all values if you don't want to use it.
- **mayanProtocol** (address) - Required - Address of Mayan final contract.
- **protocolData** (bytes) - Required - Bytes data for Mayan final contract.
### Request Example
```json
{
"tokenIn": "0x...",
"amountIn": "1000000000000000000",
"permitParams": {
"nonce": "0",
"deadline": "0",
"v": "0",
"r": "0x...",
"s": "0x..."
},
"mayanProtocol": "0x...",
"protocolData": "0x..."
}
```
### Response
#### Success Response (200)
This function is a contract call and does not return a standard HTTP response. Success is indicated by the transaction being mined without reverting.
#### Response Example
None (contract call)
```
--------------------------------
### Fetch Quote with Referral Parameters
Source: https://docs.mayan.finance/integration/referral
When fetching a quote, include your Solana referral address in the 'referrer' parameter and your desired fee rate in 'referrerBps'. Always use the Solana address for the 'referrer' parameter, irrespective of the source or destination chain.
```javascript
const quote = await fetchQuote({
...
referrer: referrerAddresses.solana,
referrerBps: 25, // example: 25 bps = 0.25%
...
});
```
--------------------------------
### Import SDK Functions
Source: https://docs.mayan.finance/link/swap
Import necessary functions and models from the SDK for cross-chain operations.
```javascript
import { fetchQuote, swapFromEvm, swapFromSolana, Quote, createSwapFromSuiMoveCalls } from '@mayanfinance/swap-sdk'
```
--------------------------------
### swapAndForwardERC20
Source: https://docs.mayan.finance/integration/forwarder-contract
Performs a swap on the source chain before bridging an ERC20 token.
```APIDOC
## swapAndForwardERC20
### Description
Performs a swap on the source chain using the input ERC20 token and then bridges the resulting middle token. This function combines a swap operation with the bridging functionality.
### Method
This is a contract function call, not an HTTP method.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **tokenIn** (address) - Required - Input token address.
- **amountIn** (uint256) - Required - Input amount.
- **permitParams** (PermitParams) - Required - Signed permission (eip-2612). Pass zero for all values if you don't want to use it.
- **swapProtocol** (address) - Required - Contract address of the swap protocol.
- **swapData** (bytes) - Required - Bytes data needed by the swap protocol.
- **middleToken** (address) - Required - The output token address from the swap protocol.
- **minMiddleAmount** (uint256) - Required - Minimum output amount of the swap step; the transaction will revert if this amount is not met.
- **mayanProtocol** (address) - Required - Address of Mayan final contract.
- **mayanData** (bytes) - Required - Bytes data for Mayan final contract.
### Request Example
```json
{
"tokenIn": "0x...",
"amountIn": "1000000000000000000",
"permitParams": {
"nonce": "0",
"deadline": "0",
"v": "0",
"r": "0x...",
"s": "0x..."
},
"swapProtocol": "0x...",
"swapData": "0x...",
"middleToken": "0x...",
"minMiddleAmount": "900000000000000000",
"mayanProtocol": "0x...",
"mayanData": "0x..."
}
```
### Response
#### Success Response (200)
This function is a contract call and does not return a standard HTTP response. Success is indicated by the transaction being mined without reverting.
#### Response Example
None (contract call)
```
--------------------------------
### React Native EVM Wallet Connection
Source: https://docs.mayan.finance/link/swap
Demonstrates how to obtain an EVM wallet provider and signer in a React Native application using WalletConnect.
```typescript
import {
useWalletConnectModal
} from '@walletconnect/modal-react-native';
...
const {
provider: evmWalletProvider
}
= useWalletConnectModal();
...
const web3Provider = new ethers.providers.Web3Provider(
ev evmWalletProvider,
);
const signer = web3Provider.getSigner(0);
```
--------------------------------
### Retrieve Swap Details using Transaction Hash
Source: https://docs.mayan.finance/integration/explorer-api
Use this cURL command to query swap details by providing the transaction hash. The API will return current statuses reflecting each step of the swap process.
```powershell
curl 'https://explorer-api.mayan.finance/v3/swap/trx/0x232bf1d5dd6e340a2e036ed0b58dbb444b56d3770d5543c7d55fecebbf0ad65e'
```
--------------------------------
### Bridge from Solana
Source: https://docs.mayan.finance/link/swap
Initiates a cross-chain swap transaction originating from the Solana network. This function requires the quote obtained from `fetchQuote`, wallet addresses, a function to sign Solana transactions, and the Solana connection object.
```APIDOC
## Bridge from Solana:
```javascript
swapTrx = await swapFromSolana(quotes[0], originWalletAddress, destinationWalletAddress, referrerAddresses, signSolanaTransaction, solanaConnection)
```
### Parameters:
- **quotes** (Quote[]) - Required - An array of quote objects obtained from `fetchQuote`.
- **originWalletAddress** (string) - Required - The wallet address on the origin chain.
- **destinationWalletAddress** (string) - Required - The wallet address on the destination chain.
- **referrerAddresses** (ReferrerAddresses) - Optional - An object containing referrer addresses for different network types (e.g., `{ evm: "YOUR EVM WALLET", solana: "YOUR SOLANA WALLET", sui: "YOUR SUI WALLET" }`).
- **signSolanaTransaction** (function) - Required - A function to sign the Solana transaction.
- **solanaConnection** (Connection) - Required - The Solana connection object.
```
--------------------------------
### Bridge from Solana
Source: https://docs.mayan.finance/link/swap
Initiate a cross-chain swap originating from the Solana network. Requires quote, wallet addresses, referrer details, and transaction signing functions.
```javascript
swapTrx = await swapFromSolana(quotes[0], originWalletAddress, destinationWalletAddress, referrerAddresses, signSolanaTransaction, solanaConnection)
```