All articles
solanaunitygamingcsharp

Solana Unity SDK: the C# client for game devs, with real wallet integration

Solana Unity SDK wraps Solana's RPC and wallet flows for C# game devs. Here's the architecture, the wallet adapter pattern, and the in-game tx flow.

The Solana Unity SDK (maintained by MagicBlock Labs) is the canonical C# client for Solana in Unity. It mirrors the web3.js mental model — RPC client, Wallet, Transaction, SPL Token helpers — but in idiomatic C# with async/await and Unity's lifecycle hooks.

Ships for WebGL, Android, iOS, and standalone builds. The same scripts run across all targets; platform-specific bits (wallet deeplinks on mobile, popups on WebGL) are handled by the SDK's wallet abstraction.

The core types

csharp
using Solana.Unity.Rpc;
using Solana.Unity.Rpc.Types;
using Solana.Unity.Wallet;
using Solana.Unity.Programs;

// RPC client (mainnet / devnet / custom URL)
IRpcClient rpc = ClientFactory.GetClient(Cluster.MainNet);

// Wallet from seed (testing) or via wallet adapter (production)
Wallet wallet = new Wallet("...your 12/24-word mnemonic...");

// Build + send a transfer
var blockHash = await rpc.GetLatestBlockHashAsync();
var tx = new TransactionBuilder()
    .SetRecentBlockHash(blockHash.Result.Value.Blockhash)
    .SetFeePayer(wallet.Account)
    .AddInstruction(SystemProgram.Transfer(
        wallet.Account.PublicKey,
        recipientPubKey,
        100_000_000ul))   // 0.1 SOL in lamports
    .Build(wallet.Account);

var sig = await rpc.SendTransactionAsync(tx);
Debug.Log($"https://solscan.io/tx/{sig.Result}");

The wallet adapter

For shipped games, you don't embed the user's seed — you use the SDK's wallet adapter, which routes signing requests to whatever wallet the player has connected:

csharp
using Solana.Unity.SDK;

// Singleton — manages connect/disconnect across the whole game
public class WalletConnectButton : MonoBehaviour
{
    public async void Connect()
    {
        // Auto-picks the right backend: Phantom deeplink on mobile,
        // browser bridge on WebGL, in-game embedded option, etc.
        var account = await Web3.Instance.LoginInGameWallet("optional-password");
        Debug.Log($"connected as {account.PublicKey}");
    }

    public async void SendInGamePurchase()
    {
        var tx = /* build your transaction as above */;
        var sig = await Web3.Wallet.SignAndSendTransaction(tx);
        Debug.Log($"purchase complete: {sig.Result}");
    }
}

Web3.Wallet is the unified abstraction — same method calls regardless of whether the player's wallet is Phantom Mobile (deeplink), Phantom WebGL extension, an in-game embedded wallet, or a Solana Mobile Stack flow.

SPL Token helpers

csharp
using Solana.Unity.Programs;
using Solana.Unity.Wallet.Utilities;

// Mint a token to a player's ATA
var mint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
var playerAta = AssociatedTokenAccountProgram
    .DeriveAssociatedTokenAccount(playerPubKey, mint);

var tx = new TransactionBuilder()
    .SetRecentBlockHash(blockHash)
    .SetFeePayer(serverWallet)
    .AddInstruction(TokenProgram.MintTo(
        mint,
        playerAta,
        100_000_000ul,        // amount
        mintAuthority))
    .Build(mintAuthority);

await rpc.SendTransactionAsync(tx);

Reading game state from on-chain accounts

csharp
// Fetch and deserialize a custom account
var info = await rpc.GetAccountInfoAsync(playerStatePda, Commitment.Confirmed);
if (info.Result?.Value != null)
{
    var bytes = Convert.FromBase64String(info.Result.Value.Data[0]);
    // Parse with Borsh or your custom deserializer
    var playerState = BorshDeserializer.Deserialize<PlayerState>(bytes);
    Debug.Log($"player level: {playerState.Level}, gold: {playerState.Gold}");
}

For Anchor programs, the SDK's code-generation pipeline turns an IDL into typed C# clients similar to how Anchor's TS client works. solana-anchorgen-cs (or the SDK's built-in tool) reads an Anchor IDL and emits matching C# files.

Platform notes

  • WebGL. Browser-side, the SDK bridges to the standard wallet-adapter ecosystem. Phantom, Solflare, Backpack browser extensions all work.
  • Android. Uses Solana Mobile Stack's Mobile Wallet Adapter — intent URIs deeplink to installed wallet apps for signing.
  • iOS. Same MWA flow as Android. Phantom and Solflare iOS apps are supported.
  • Standalone (PC/Mac). The in-game embedded wallet flow is the most common — players generate or import a keypair held by the game with the SDK's secure storage.

MagicBlock integration

Because the SDK is maintained by MagicBlock, it ships first- class hooks into ephemeral rollups — the delegate / undelegate flow exposed as Unity-native calls. For real-time games (FPS, RTS, twitch combat), this is the combination that makes "every action on-chain" actually playable.

References

If you're shipping a Unity game on Solana, this SDK is the only credible answer. Cross-platform, wallet-agnostic, and Anchor-aware.

Solana Unity SDK: the C# client for game devs, with real wallet integration | devrels.xyz