❗
This SDK is currently in beta. Please report any issues you encounter by creating an issue in the aptos-labs/unity-sdk repository.
Aptos Unity SDK (Beta)
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 Version | Supported |
---|---|
.NET Standard 2.1 | ✅ |
Installation
Install via Unity Package Manager (UPM)
- Open the Unity Package Manager (
Window
>Package Manager
). - Click on the
+
button and selectAdd package from git URL...
. - Enter the URL of the Aptos Unity SDK path in this repository:
https://github.com/aptos-labs/unity-sdk.git?path=/Packages/com.aptoslabs.aptos-unity-sdk
Install via unitypackage
- Go to the
aptos-labs/unity-sdk Releases
and download the latest release. - Drag and drop the
.unitypackage
file into your Unity project.
Usage
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.
Program.cs
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);
}
}