Skip to main content

Embedded Wallets SDK for Unreal Engine

Overview

MetaMask Embedded Wallets SDK (formerly Web3Auth Plug and Play) provides a seamless authentication experience for Unreal Engine game applications with social logins, external wallets, and more. Using our Unreal SDK written in C++, you can easily connect users to their preferred wallets and manage authentication state across all mobile platforms.

Requirements

  • Unreal Engine v5.3.1 with Xcode 15
  • Epic Game Launcher to download Unreal library
  • Basic knowledge of C++ and Unreal Engine Development

Prerequisites

tip

See the dashboard setup guide to learn more.

Installation

Install the Web3Auth Unreal Engine SDK using one of the following methods:

Git clone installation

Follow these instructions to install the web3auth-unreal-sdk plugin:

  1. Close your existing Unreal Engine app.
  2. Create a directory in your app root called Plugins.
  3. Clone with:
git clone https://github.com/Web3Auth/web3auth-unreal-sdk/tree/main/Plugins/Web3AuthSDK ./Plugins/Web3AuthSDK
  1. Open UE5 Editor, navigator to MenuEditPlugins, check the option to enable Web3AuthSDK.
  2. Start your app & it will ask to compile the plugin. Proceed with that.

Manual installation

Download the Unreal Package from our latest release and import the package file into your existing Unreal Engine project.

1. Configure Embedded Wallets project

1.1 Go to the Embedded Wallets dashboard, create or select an Web3Auth project: 1.2 Add {{SCHEMA}}://{YOUR_APP_PACKAGE_NAME} to Whitelist URLs. 1.3 Copy the Client ID for usage later.

To setup Android sdk and ndk for unreal editor. Please see the unreal documentation.

  • To add redirect URI into your Android app, open the <Project-path>/Plugins/Web3AuthSDK/Source/Web3AuthSDK_Android.xml file.
  • Find the <androidManifestUpdates> tag and inside that, will be a <data> tag element. Replace the existing redirect URI with one that you have registered on your Embedded Wallets dashboard.

Configure your iOS deep link settings in the appropriate configuration files. Make sure the redirect URI matches what you have registered in your Embedded Wallets dashboard.

Initialize Web3Auth

1. Initialize Embedded Wallets instance

Initialize the Web3Auth SDK in your Unreal project:

#include "Web3AuthSDK.h"

void AYourGameMode::BeginPlay()
{
Super::BeginPlay();

// Initialize Web3Auth
FWeb3AuthOptions Options;
Options.ClientId = TEXT("YOUR_CLIENT_ID"); // Get your Client ID from Embedded Wallets/Web3Auth Dashboard
Options.Network = TEXT("sapphire_mainnet"); // or "sapphire_devnet"
Options.RedirectUrl = TEXT("YOUR_SCHEMA://YOUR_APP_PACKAGE_NAME");

UWeb3AuthSDK::GetInstance()->Initialize(Options);
}

2. Setup authentication callbacks

Set up callbacks to handle authentication responses:

void AYourGameMode::SetupWeb3AuthCallbacks()
{
// Bind login success callback
UWeb3AuthSDK::GetInstance()->OnLoginSuccess.AddDynamic(this, &AYourGameMode::OnWeb3AuthLoginSuccess);

// Bind login error callback
UWeb3AuthSDK::GetInstance()->OnLoginError.AddDynamic(this, &AYourGameMode::OnWeb3AuthLoginError);

// Bind logout callback
UWeb3AuthSDK::GetInstance()->OnLogout.AddDynamic(this, &AYourGameMode::OnWeb3AuthLogout);
}

UFUNCTION()
void AYourGameMode::OnWeb3AuthLoginSuccess(const FString& PrivateKey, const FString& PublicAddress)
{
UE_LOG(LogTemp, Warning, TEXT("Web3Auth Login Success - Private Key: %s"), *PrivateKey);
}

UFUNCTION()
void AYourGameMode::OnWeb3AuthLoginError(const FString& Error)
{
UE_LOG(LogTemp, Error, TEXT("Web3Auth Login Error: %s"), *Error);
}

UFUNCTION()
void AYourGameMode::OnWeb3AuthLogout()
{
UE_LOG(LogTemp, Warning, TEXT("Web3Auth Logout Success"));
}

Advanced configuration

The Embedded Wallets Unreal SDK offers a rich set of advanced configuration options:

tip

See the advanced configuration sections to learn more about each configuration option.

FWeb3AuthOptions Options;
Options.ClientId = TEXT("YOUR_CLIENT_ID");
Options.Network = TEXT("sapphire_mainnet"); // or "sapphire_devnet"
Options.RedirectUrl = TEXT("YOUR_SCHEMA://YOUR_APP_PACKAGE_NAME");

UWeb3AuthSDK::GetInstance()->Initialize(Options);

Blockchain integration

Web3Auth is blockchain agnostic, enabling integration with any blockchain network. Out of the box, Web3Auth offers robust support for both Solana and Ethereum.

Ethereum integration

For Ethereum integration, you can get the private key and use it with Ethereum libraries:

UFUNCTION()
void AYourGameMode::OnWeb3AuthLoginSuccess(const FString& PrivateKey, const FString& PublicAddress)
{
// Use private key for Ethereum transactions
UE_LOG(LogTemp, Warning, TEXT("Ethereum Private Key: %s"), *PrivateKey);
UE_LOG(LogTemp, Warning, TEXT("Ethereum Address: %s"), *PublicAddress);
}

Solana integration

For Solana integration, you can get the Ed25519 private key:

UFUNCTION()
void AYourGameMode::OnWeb3AuthLoginSuccess(const FString& PrivateKey, const FString& PublicAddress)
{
// Get Ed25519 private key for Solana
FString Ed25519PrivKey = UWeb3AuthSDK::GetInstance()->GetEd25519PrivKey();
UE_LOG(LogTemp, Warning, TEXT("Solana Ed25519 Private Key: %s"), *Ed25519PrivKey);
}