The Aptos .NET SDK is a library that provides a convenient way to interact with the Aptos blockchain using C# under the .NET framework. The SDK is designed to offer all the necessary tools to build applications that interact with the Aptos blockchain.
Initialize an instance of the AptosClient
class to interact with the Aptos blockchain. You can use a pre-defined network configuration from the Networks
class.
// 1. Import the Aptos namespace
using Aptos;
// 2. Initialize the Aptos client
var config = new AptosConfig(Networks.Mainnet);
var client = new AptosClient(config);
// 3. Use the client to interact with the blockchain!
var ledgerInfo = await client.Block.GetLedgerInfo();
To sign and submit a transaction, you can build a payload using the AptosClient
and sign it with an Account
signer.
using Aptos;
// 1. Initialize the Aptos client
var config = new AptosConfig(Networks.Mainnet);
var client = new AptosClient(config);
// 2. Create a new account
var account = Account.Generate();
// 2. Create a transaction payload
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);
The SDK is published onto NuGet where you can install it using the following command:
dotnet add package Aptos
Find the Aptos Unity SDK repository at aptos-labs/unity-sdk.
Window
> Package Manager
).+
button and select Add package from git URL...
.https://github.com/aptos-labs/unity-sdk.git?path=/Packages/com.aptoslabs.aptos-unity-sdk
aptos-labs/unity-sdk Releases
and download the latest release. .unitypackage
file into your Unity project.To install the Aptos SDK into your Godot project, you will need to add the Aptos SDK into your Godot project's .csproj
file.
.csproj
file in the root of your Godot project.<ItemGroup>
section of the .csproj
file. If it doesn't exist, create it the <ItemGroup>
section.<Project Sdk="Godot.NET.Sdk/4.3.0">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>AptosSDKExample</RootNamespace>
</PropertyGroup>
<!-- START: Add these lines -->
<ItemGroup>
<PackageReference Include="Aptos" Version="0.0.1-beta" />
</ItemGroup>
<!-- END -->
</Project>
using Aptos;
public partial class MyClass : Node
{
public override void _Ready()
{
var client = new AptosClient(Networks.Mainnet);
var ledgerInfo = await client.Block.GetLedgerInfo();
Console.WriteLine($"Ledger Block Height: {ledgerInfo.BlockHeight}");
}
}
The entire API reference can be found here: API Reference
Examples can be found in the Aptos.Examples
project. Run the examples by using the following command:
dotnet run --project ./Aptos.Examples --framework net8.0
This will prompt the follow console. You can select an example to run by entering the corresponding number or using the arrow keys to navigate the menu.
To release a new version of the SDK, you can bump the version in the Directory.Build.props
file and push the changes to the main
branch. The GitHub Actions workflow will automatically publish the new version to NuGet.