Skip to main content
Version: v2

Swap tokens

The swap flow allows players to swap tokens on Immutable zkEVM.
Unity MarketplaceUnity Marketplace
đź’ˇWho is this for?
Developers who want to build an in-game marketplace in Unity.
đź’ˇAllowlisted tokens
Only tokens that have been verified will be displayed on the widgets. To allowlist an ERC-20 token please follow our Asset Verification procedure.
For additional questions, please contact our Developer Support team.

Overview​

The swap widget, powered by Quickswap, facilitates token exchanges on Immutable zkEVM.

The Immutable Marketplace package generates the URL required to access the widget.

Generating the swap URL​

To generate the swap URL, provide the following details:

  • Environment – Choose either sandbox or production.
  • Publishable key – Available from Immutable Hub. Follow the steps on this page to create your publishable key.
using Immutable.Marketplace;
using UnityEngine;

public class MarketplaceExample : MonoBehaviour
{
async void Start()
{
try
{
string link = LinkFactory.GenerateSwapLink(
environment: Environment.Sandbox,
publishableKey: "YOUR_PUBLISHABLE_KEY"
);
Debug.Log($"Link: {link}");

// Open the generated link in the default browser
Application.OpenURL(link);
}
catch (System.Exception e)
{
Debug.LogError($"Error getting the swap link: {e.Message}");
}
}
}

Configuration​

You can pass optional configurations to the swap widget using the GenerateSwapLink function. The main configurations are provided through the SwapQueryParams struct.

The SwapQueryParams struct allows you to define the configuration for the swap flow. Here's a list of the available fields:

ParameterDescription
FromTokenAddressThe address of the token being swapped from (default: null).
ToTokenAddressThe address of the token being swapped to (default: null).

Here's an example of how to use the GenerateSwapLink function with the SwapQueryParams struct:

var link = LinkFactory.GenerateSwapLink(
environment: Environment.Sandbox,
publishableKey: "YOUR_PUBLISHABLE_KEY",
queryParams: new SwapQueryParams
{
FromTokenAddress = "0x1234...abcd",
ToTokenAddress = "0xabcd...1234"
}
);

For more information, refer to Swap tokens.


Related content