Connection
This guide explains how to implement wallet connection functionality using the Cross Unity SDK.
SDK Initialization
// Create a CrossSdkConfig and enter your project information.
var config = new CrossSdkConfig
{
projectId = "your_project_id",
metadata = new Metadata(
name: "Your App Name",
description: "App Description",
url: "https://yourapp.com",
iconUrl: "https://yourapp.com/icon.png"
)
};
// Initialize the CrossSdk asynchronously.
await CrossSdk.InitializeAsync(config);
Basic Connection
1. Connect Wallet
// Request wallet connection.
CrossSdk.Connect();
2. Switch Network
// Show a network (chain) selection modal so the user can select a network.
CrossSdk.OpenModal(ViewType.NetworkSearch);
3. Network Status
// Use CrossSdk.NetworkController or CrossSdk state to check the current chain ID and connection status.
var chainId = CrossSdk.NetworkController?.ActiveChain?.ChainId;
bool isConnected = CrossSdk.IsAccountConnected;
Debug.Log($"Chain ID: {chainId}");
Debug.Log($"Network Status: {(isConnected ? "Connected" : "Disconnected")}");
4. Disconnect Wallet
// Disconnect the wallet.
await CrossSdk.DisconnectAsync();
Updated 28 days ago