Swapping tokens
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.
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.
Generating the swap widget URL
To generate the swap URL:
- Set the desired environment (e.g., sandbox or production).
- Provide your publishable key from Immutable Hub.
- 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.