Skip to main content

On-ramping tokens

This tutorial step covers how to use the on-ramp flow to purchase tokens with fiat currency (e.g., USD) using the Unity Marketplace package.

Players can use this flow to add funds when they do not have enough tokens to purchase NFTs in your marketplace.
On-ramping tokens in UnityOn-ramping tokens in Unity
💡Prerequisite step
Before continuing with this step, ensure you have completed the previous fulfilling orders step of this tutorial series.

Overview

The Transak on-ramp widget allows players to purchase tokens with fiat currency, such as using a credit or debit card to acquire in-game ERC-20 tokens.

You can integrate this widget into your game using one of two approaches:

  1. Direct players to their default browser to open the Transak widget.
  2. Embed the widget within your game using a WebView component for a seamless in-game experience.

In the sample game, option 2 was chosen, utilising the paid Vuplex WebView solution for its robust and reliable features.

On-ramp flow

Displaying the on-ramp widget

The Unity Marketplace package provides a function to generate the Transak on-ramp widget URL, which you can customise with specific configuration options to tailor the experience. In this example, we also use the Unity Passport package to retrieve the logged-in player's email and wallet address, which are included in the generated URL.

using UnityEngine;
using System.Linq;
using Immutable.Marketplace;
using Immutable.Passport;
using Environment = Immutable.Marketplace.Environment;

public class OnRamp : MonoBehaviour
{
public async void OnRampClicked()
{
var email = await Passport.Instance.GetEmail(); // Get the logged-in player's email
var walletAddress = await Passport.Instance.ZkEvmRequestAccounts(); // Get the logged-in player's wallet address

var link = LinkFactory.GenerateOnRampLink(
environment: Environment.Sandbox,
email: email,
address: walletAddress.FirstOrDefault(),
queryParams: new OnRampQueryParams
{
DefaultFiatCurrency = "AUD",
DefaultFiatAmount = "20",
DefaultCryptoCurrency = "USDC"
}
);

m_WebViewPrefab.WebView.LoadUrl(link); // Open the link in a WebView
}
}

For more details on customising the on-ramp experience, refer to the Unity On-ramp tokens documentation.

Next steps

You've now enabled players to purchase tokens using fiat currency through the on-ramp flow, ensuring they have funds to buy NFTs in your marketplace. Next, learn how to use the swap flow to allow players to exchange one token for another. Click next below to continue the tutorial.


Related content