Unity-Sui-SDK is a sample example to help developers integrate Sui blockchain technology into their C# and Unity projects.
Plugins/
:: This directory contains the project's library files, including libsui_rust_sdk.dylib library to integrate with SUI network.SuiUnitySDK/
:: The core SDK files and scripts.Samples/
:: Includes sample scenes or scripts demonstrating how to use the SDK.TextMesh Pro/
: This directory contains the TextMesh Pro package assets.
- Compatibility with main, dev, and test networks.
- Integration with Sui blockchain using native libraries.
- Cross-platform support (macOS, Windows, Linux).
- Mint new NFTs.
- Transfer NFTs to other addresses.
- Retrieve wallet objects related to NFTs.
- Conversion between raw and managed data structures for NFT objects.
- Basic serialization and deserialization of Sui types.
- Support for various Sui types including integers, floats, booleans, strings, and addresses.
- Conversion of Sui types to BCS (Binary Canonical Serialization) format.
- Create and manage multisig wallets.
- Create transactions from multisig wallets.
- Sign and execute transactions using multisig wallets.
- Handling of multisig data structures and transaction results.
- Create and manage transaction builders.
- Add various types of commands to transactions (e.g., move call, transfer object, split coins, merge coins).
- Execute transactions with or without a sponsor.
- Singleton pattern for easy access to wallet functionalities.
- Generate new wallets with specified key schemes and word lengths.
- Import wallets from private keys.
- Import wallets from mnemonics.
- List all wallets.
- Display wallet details.
- Generate and add new keys to the wallet.
Platforms | Unity Version | Status |
---|---|---|
Mac | Unity 2022 | Fully Tested |
This guide provides step-by-step instructions for installing and setting up on macOS platforms. Ensure you have the following prerequisites installed to build the project:
- Visual Studio Code with C# development environment
- Install Sui Follow this guide to install Sui https://docs.sui.io/guides/developer/getting-started/sui-install
Run follow command to setting Environment before testing:
- Check Sui Client Environment:
Sui client envs
NOTE:If you dont have DevNet Please Run CMD :
sui client new-env --alias devnet --rpc https://fullnode.devnet.sui.io:443
- Switch to devnet network:
sui client switch --env devnet
- Check current network:
sui client active-env
NOTE: The return should be devnet
- Get the active address:
sui client active-address
- Request token:
sui client faucet
NOTE: Wait for 60s to get the tokens
- Check the gas coin objects for the active address:
sui client gas
- Via 'Add package from git URL' in Unity Package Manager
- Download the latest sui-unity-sdk.unitypackage from the releases: https://github.com/VAR-META-Tech/Unity-Sui-SDK/releases
Note: For the NFTLib.cs you need to build the NFT package from https://github.com/VAR-META-Tech/Move-Sui-SDK and replace the received NFT_PACKAGE_ID and NFT_OBJECT_TYPE
The SDK comes with several examples that show how to leverage the Rust2C-Sui-SDK to its full potential. The examples include Wallet Creation and Management, Token Transfers, NFT Minting, Account Funding, and Multi-signature.
The SuiClient
class provides methods to build and switch between different Sui networks (testnet, devnet, mainnet). Below are some examples of how to use the SuiClient
class.
To build the testnet environment:
bool success = SuiClient.BuildTestnet();
if (success)
{
Debug.Log("Testnet built successfully.");
}
else
{
Debug.LogError("Failed to build testnet.");
}
To build the devnet environment:
bool success = SuiClient.BuildDevnet();
if (success)
{
Debug.Log("Devnet built successfully.");
}
else
{
Debug.LogError("Failed to build devnet.");
}
To build the mainnet environment:
bool success = SuiClient.BuildMainnet();
if (success)
{
Debug.Log("Mainnet built successfully.");
}
else
{
Debug.LogError("Failed to build mainnet.");
}
The SuiWallet
class provides various functionalities to manage wallets in your Unity project. Below are some examples of how touse the SuiWallet
class.
To generate a new wallet with a specified key scheme and word length:
SuiWallet.WalletData newWallet = SuiWallet.GenerateWallet("ED25519", "12");
newWallet.Show();
To import a wallet using a private key:
bool success = SuiWallet.ImportFromPrivateKey("your_private_key_here");
if (success)
{
Debug.Log("Wallet imported successfully.");
}
else
{
Debug.LogError("Failed to import wallet.");
}
To import a wallet using a mnemonic phrase:
bool success = SuiWallet.ImportFromMnemonic("your_mnemonic_phrase_here");
if (success)
{
Debug.Log("Wallet imported successfully.");
}
else
{
Debug.LogError("Failed to import wallet.");
}
To list all wallets:
SuiWallet.WalletData[] wallets = SuiWallet.LoadWallets();
foreach (var wallet in wallets)
{
wallet.Show();
}
To generate and add a new key to the wallet:
SuiWallet.GenerateAndAddNew();
The SuiTransactionBuilder
class allows you to create and manage transactions. Below are some examples of how to use the SuiTransactionBuilder
class.
To create a new transaction:
SuiTransactionBuilder.CreateBuilder();
To add a move call command to the transaction:
SuiTypeTags typeTags = SuiTransactionBuilder.CreateTypeTags();
SuiAgruments arguments = SuiTransactionBuilder.CreateArguments();
SuiTransactionBuilder.AddMoveCallCommand("package_id", "module_name", "function_name", typeTags, arguments);
To add a transfer object command to the transaction:
SuiAgruments agreements = SuiTransactionBuilder.CreateArguments();
SuiAgruments recipient = SuiTransactionBuilder.CreateArguments();
SuiTransactionBuilder.AddTransferObjectCommand(agreements, recipient);
To execute the transaction:
string result = SuiTransactionBuilder.ExecuteTransaction("sender_address", 1000);
Debug.Log(result);
To execute the transaction with a sponsor:
string result = SuiTransactionBuilder.ExecuteTransactionAllowSponser("sender_address", 1000, "sponsor_address");
Debug.Log(result);
The SuiBCS
class provides methods for basic serialization and deserialization of Sui types. Below are some examples of how to use the SuiBCS
class.
To serialize data of a specific Sui type:
string data = "12345";
SuiPure serializedData = SuiBCS.BscBasic(SuiBCS.SuiType.U64, data);
IntPtr serializedPtr = serializedData.GetData();
The SuiMultisig
class provides functionalities to create and manage multisig wallets. Below are some examples of how to use the SuiMultisig
class.
To create a new multisig wallet:
SuiMultisig.CreateMultisigWallet(new string[] { "address1", "address2", "address3" }, 2);
To create a transaction from a multisig wallet:
SuiMultisig.CreateTransaction();
To sign and execute a transaction using a multisig wallet:
string result = SuiMultisig.SignAndExecuteTransaction(SuiTransactionBuilder, "signer_address");
Debug.Log(result);
The SuiNFT
class provides functionalities to mint, transfer, and retrieve NFT-related wallet objects. Below are some examples of how to use the SuiNFT
class.
To mint a new NFT:
string result = SuiNFT.Mint_NFT("sender_address", "NFT Name", "NFT Description", "NFT URI");
Debug.Log("Mint Result: " + result);
To transfer an NFT to another address:
string result = SuiNFT.Transfer_NFT("sender_address", "nft_id", "recipient_address");
Debug.Log("Transfer Result: " + result);
To retrieve wallet objects related to NFTs:
List<SuiNFT.CSuiObjectData> walletObjects = SuiNFT.Get_wallet_objects("wallet_address");
foreach (var obj in walletObjects)
{
Debug.Log("Object ID: " + obj.object_id);
Debug.Log("Version: " + obj.version);
Debug.Log("Digest: " + obj.digest);
Debug.Log("Type: " + obj.type_);
Debug.Log("Owner: " + obj.owner);
Debug.Log("Previous Transaction: " + obj.previous_transaction);
Debug.Log("Storage Rebate: " + obj.storage_rebate);
Debug.Log("Display: " + obj.display);
Debug.Log("Content: " + obj.content);
Debug.Log("BCS: " + obj.bcs);
}
This project is licensed under the Apache-2.0 License. Refer to the LICENSE.txt file for details.