Thirdweb Manager

The ThirdwebManager is a prefab that provides a convenient way to instantiate the ThirdwebClient, and contains helper functions to create contracts and wallets. Add the prefab to your scene and the client will persist throughout your game's lifecycle, keeping track of your connected wallets.

It is entirely optional, and you can opt to use the .NET SDK directly if you prefer to do so.

If you are wrapping the SDK, we recommend making your own Manager inspired by ThirdwebManager.cs, specifically for ThirdwebClient initialization.

Configuration

Configure ThirdwebManager through the Unity Inspector window.

Below is a list of all the settings you can adjust.

Client

This section involves the required thirdweb client settings to configure the SDK:

  • Client ID: Thirdweb API Key. Used to access thirdweb services such as RPC, Storage, and Account Abstraction.
  • Bundle ID: The bundle ID used to access thirdweb services from native platforms. Should be the same as the bundle ID in your Unity project, e.g., com.companyname.gamename.
  • Create API Key: A link to create a new API key if you don't have one.

Preferences

This section allows you to define the default preferences for the SDK:

  • Initialize On Awake: Whether the SDK should initialize on awake or not. If not, you can call ThirdwebManager.Instance.Initialize() to initialize it manually.
  • Show Debug Logs: Whether to show thirdweb SDK debug logs.
  • Opt Out Usage Analytics: Whether to opt out of Connect usage analytics, such as the number of wallets connected to your game.

Misc

This section allows you to customize the SDK's behavior:

  • Supported Chains: A list of chains that the wallets should be able to connect to by default when using WalletConnect as a wallet provider.
  • Redirect Page HTML Override: Raw HTML to override the default redirect page when connecting to InAppWallet or EcosystemWallet providers.

Debug

This section allows you to find helpful information:

  • Log Active Wallet Info: Logs the active (last connected) wallet's information such as its address.
  • Open Documentation: Opens the thirdweb SDK documentation in your default browser.

Interacting with the ThirdwebManager

Once your ThirdwebManager is set up, you can interact with it using the following methods:

Initialize (If not set to Initialize On Awake)

ThirdwebManager.Instance.Initialize();

Initializes the SDK with the settings specified in the Unity Inspector.

GetContract

var contract = await ThirdwebManager.Instance.GetContract("contract-address", chainId, "optional-contract-abi");
var result = await contract.Read<string>("name");

Returns a ThirdwebContract instance that can be used to interact with a smart contract.

GetActiveWallet

var wallet = ThirdwebManager.Instance.GetActiveWallet();

Returns the currently active wallet as an IThirdwebWallet.

SetActiveWallet

ThirdwebManager.Instance.SetActiveWallet(wallet);

Sets the specified wallet as the active wallet.

GetWallet

var wallet = ThirdwebManager.Instance.GetWallet("wallet-address");

Returns a wallet from the manager's wallet mapping by its address.

AddWallet

var wallet = await ThirdwebManager.Instance.AddWallet(wallet);

Adds a wallet to the manager's wallet mapping and returns the added wallet.

RemoveWallet

ThirdwebManager.Instance.RemoveWallet("wallet-address");

Removes a wallet from the manager's wallet mapping by its address.

ConnectWallet

var walletOptions = new WalletOptions(WalletProvider.PrivateKeyWallet, 421614);
var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions);
var address = await wallet.GetAddress();

Connects a wallet based on the specified WalletOptions and returns an IThirdwebWallet instance that can be used to interact with the blockchain.

UpgradeToSmartWallet

var smartWallet = await ThirdwebManager.Instance.UpgradeToSmartWallet(wallet, chainId, smartWalletOptions);

Upgrades the specified wallet to a SmartWallet, returning a SmartWallet instance.

LinkAccount

var linkedAccounts = await ThirdwebManager.Instance.LinkAccount(mainWallet, walletToLink, otp, chainId, jwtOrPayload);

Links another InAppWallet account to the main wallet and returns a list of linked accounts, allowing you to login with either authentication method later.

Child Prefabs

InAppWalletModal

The InAppWalletModal prefab is a simple and customizable OTP verification modal for InAppWallet providers. It is used to verify and finalize the user's wallet connection.

It will be automatically activated when connecting to an InAppWallet provider.

EcosystemWalletModal

Similar use case as InAppWalletModal, but for EcosystemWallet providers.

WalletConnectModal

The WalletConnectModal prefab is an out-of-the-box WalletConnect modal that can be used to connect to 400+ wallets.

It will be automatically activated when connecting to a WalletConnect provider.

What Now?

Explore the .NET SDK to learn more about interacting with smart contracts, wallets, storage, RPC, account abstraction, and more.