Skip to content

Unity SDK

Integrate Aptos Web3 capabilities within your Unity applications. The goal of this SDK is to provide a set of tools for developers to build Web3 games using the Unity game engine.

Supported Features

  • Support for the Aptos .NET SDK

    • Binary Canonical Serialization (BCS) encoding and decoding
    • Ed25519, SingleKey, MultiKey, and Keyless signer support
    • Utilities for transaction building, signing, and submission
    • Abstractions over the Aptos Fullnode and Indexer APIs
    • Aptos Names (ANS) support for resolution and lookup

Compatibility

.NET VersionSupported
.NET Standard 2.1
  1. Open the Unity Package Manager (Window > Package Manager).
  2. Click on the + button and select Add package from git URL....
  3. Enter the URL of the Aptos Unity SDK path in this repository:
Terminal window
https://github.com/aptos-labs/unity-sdk.git?path=/Packages/com.aptoslabs.aptos-unity-sdk
  1. Go to the aptos-labs/unity-sdk Releases and download the latest release.
  2. Drag and drop the .unitypackage file into your Unity project.

Set up your Aptos client by adding the Aptos namespace and instantiating an AptosUnityClient. You can use a predefined configuration from Networks or configuring your own.

using UnityEngine;
using Aptos;
class Example : MonoBehaviour
{
public void Start()
{
PrintLedgerInfo();
}
async void PrintLedgerInfo() {
var client = new AptosUnityClient(Networks.Mainnet);
var ledgerInfo = await client.Block.GetLedgerInfo();
Debug.Log(ledgerInfo.BlockHeight);
}
}

To interact with the blockchain, you will need to create a signer and build a transaction.

using UnityEngine;
using Aptos;
class Example : MonoBehaviour
{
public async void Start()
{
var client = new AptosUnityClient(Networks.Mainnet);
// 1. Create a signer
var signer = Account.Generate();
// 2. Build the transaction
var transaction = await client.Transaction.Build(
sender: account,
data: new GenerateEntryFunctionPayloadData(
function: "0x1::aptos_account::transfer_coins",
typeArguments: ["0x1::aptos_coin::AptosCoin"],
functionArguments: [account.Address, "100000"]
)
);
// 3. Sign and submit the transaction
var pendingTransaction = client.Transaction.SignAndSubmitTransaction(account, transaction);
// 4. (Optional) Wait for the transaction to be committed
var committedTransaction = await client.Transaction.WaitForTransaction(pendingTransaction);
}
}