Unity

If you are selling an NFT in your game, it is important to check the following :

Is user authenticated with a email?

using UnityEngine;
using RGN;

public class WalletExamples : MonoBehaviour
{
    private bool IsUserAuthenticatedWithEmail()
    {
        return RGNCoreBuilder.I.CurrentAuthState.AuthProvider == EnumAuthProvider.Email;
    }
}

Is user has a wallet?

using UnityEngine;
using RGN;
using RGN.Modules.Wallets;
using System.Threading.Tasks;

public class WalletExamples : MonoBehaviour
{
    private async Task<bool> IsUserHasBlockchainRequirement()
    {
        bool hasRequirement = await WalletsModule.I.IsUserHasBlockchainRequirementAsync();
        return hasRequirement;
    }
}

Create wallet

using UnityEngine;
using RGN.Modules.Wallets;

public class WalletExamples : MonoBehaviour
{
    private void CreateWallet()
    {
        // This will open the OAuth form for the wallet creation
        WalletsModule.I.CreateWallet();
    }
{

Example flow for NFT purchase

using System.Collections.Generic;
using UnityEngine;
using RGN;
using RGN.Modules.Wallets;
using RGN.Modules.SignIn;
using RGN.Modules.Store;

public class WalletExamples : MonoBehaviour
{
    private async void BuyNFTVirtualItem()
    {
        bool authWithEmail = RGNCoreBuilder.I.CurrentAuthState.AuthProvider == EnumAuthProvider.Email;
        if (!authWithEmail)
        {
            EmailSignInModule.I.TryToSignIn();
            return;
        }

        bool hasBlockchainRequirement = await WalletsModule.I.IsUserHasBlockchainRequirementAsync();
        if (!hasBlockchainRequirement)
        {
            WalletsModule.I.CreateWallet();
            return;
        }

        List<string> virtualItemIds = new List<string> { "myNftVirtualItemId" };
        PurchaseResult purchaseResult = await StoreModule.I.BuyVirtualItemsAsync(virtualItemIds);
    }
}

Last updated