Unity SDK

Overview

The Ramper Unity SDK is a no-code integration solution for Unity projects to have embedded Web3 wallet and dapp-to-wallet signatures signing within their app, allowing their users to instantly own a self-custodial wallet just by signing in with Email or SSO (Gmail, Facebook, Twitter, Apple ID, Telegram). Onboarding Web2 users to onchain has been never this easy!

Supported platform

  • Android

  • iOS

Installation

Download and Import: Download the unity-ramper-latest.unitypackage and import it into your Unity project.

Setup

After installation, you need to configure the SDK settings.

1. Open the Settings Asset:

Go to the Unity top menu and select Ninety Eight > Ramper SDK Setting.

2. Configure the Settings:

  • App ID: Enter the appId provided by Ninety Eight.

  • Game Slug: Enter the gameSlug provided by Ninety Eight.

  • Is Debug: Toggle this option to enable or disable debug logs.

Demo Wallet: For testing in the Unity editor, enter a fixed wallet address to simulate wallet interactions. These settings ensure that your SDK is properly configured for use within your Unity project.

Usage

Connecting to a Wallet

Basic login method

Use the Login method to connect to a Web3 wallet. This method opens a web view for the user to authenticate their wallet.

Parameters

  • message: The message to sign with the wallet. An empty string is acceptable.

import { init, signIn } from '@ramper-v2/viction'
import { getWalletModel, User, WALLET_PROVIDER } from '@ramper-v2/core'
import { ethers } from '@ethers'

await init({
  appId: 'missing_app_id',
  appName: 'Viction Test App',
  walletProviders: [],
  defaultTokenAddresses: [],
  theme: 'dark',
  network: 'mainnet',
  authProviders: ['google', 'facebook', 'email'],
})

Login direct with Provider

LoginDirect is a function that supports custom social login buttons in your app.

Parameters

  • provider: The provider directs to the login method for Ramper.

  • message: The message to sign with the wallet. An empty string is acceptable.

C98SDK.Ins.LoginDirect("google", message, dataCallback =>
{
   if (connectCallback.success)
    {
        Debug.Log("Successfully connected: " + connectCallback.data.wallets.ethereum.publicKey);
    }
    else
    {
        Debug.LogError("Failed to connect. error: " + connectCallback.error);
    }
});

We support the four most common providers: google, apple, facebook and email.

Signing a Message

The SignMessage method allows you to sign messages, which is essential for authentication and transaction verification in Web3 applications.

C98SDK.Ins.SignMessage("Your message here", (signMessageCallback) =>
{
    if (signMessageCallback.success)
    {
        Debug.Log("Message signed: " + signMessageCallback.signature);
    }
    else
    {
        Debug.LogError("Failed to sign message.");
    }
});

Signing a Transaction

You can sign transactions using the SignTransaction method. This is critical for executing actions on the blockchain.

C98SDK.Ins.SignTransaction(transactionData, (signTransactionCallback) =>
{
    if (signTransactionCallback.success)
    {
        Debug.Log("Transaction signed: " + signTransactionCallback.transactionHash);
    }
    else
    {
        Debug.LogError("Failed to sign transaction.");
    }
});

Dependencies

  • Unity: Version 2020.3 or higher.

  • WebView: The SDK leverages a web view for user authentication.

Last updated