Skip to main content

Swapping tokens

Learn how to integrate the swap flow, enabling players to exchange tokens on Immutable zkEVM. This feature provides another way for players to acquire your game's ERC-20 tokens for purchasing NFTs in your marketplace.
Swapping tokens in UnitySwapping tokens in Unity
💡Prerequisite step
Before continuing with this step, ensure you have completed the previous on-ramping tokens step of this tutorial series.

Overview

The swap flow allows players to exchange one token for another on the Immutable zkEVM network, providing an alternative means of obtaining your in-game currency. This functionality is powered by Quickswap.

💡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 support team on Discord.

In this section, we will use the Immutable Marketplace package to generate the swap URL and open it in a browser with the Application.OpenURL(link) function. You can refer to the sample game code for an example of how to implement this.

Swap flow

Generating the swap widget URL

To generate the swap URL:

  1. Set the desired environment (e.g., sandbox or production).
  2. Provide your publishable key from Immutable Hub.
  3. Optionally, define the tokens for the swap, such as your in-game ERC-20 token.

Follow this guide to create your publishable key.

using UnityEngine;
using Immutable.Marketplace;
using Environment = Immutable.Marketplace.Environment;

public class Swap : MonoBehaviour
{
public void OnSwapClicked()
{
var link = LinkFactory.GenerateSwapLink(
environment: Environment.Sandbox,
publishableKey: "YOUR_PUBLISHABLE_KEY",
queryParams: new SwapQueryParams
{
ToTokenAddress = "YOUR_GAME_ERC20_TOKEN_ADDRESS"
}
);

Application.OpenURL(link);
}
}

For additional customisation, see the Unity Swap tokens documentation.

Next steps

Players can now swap tokens for your in-game currency, ensuring they have the funds needed to purchase NFTs in your marketplace. Continue to the final step of this tutorial series to learn about bridging tokens.


Related content