Skip to content

VAR-META-Tech/Unity-Sui-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

645bca632d1c27a85cee236d_sui-logo8d3c44e

Unity-Sui-SDK

Unity-Sui-SDK is a sample example to help developers integrate Sui blockchain technology into their C# and Unity projects.

Project Structure

  1. Plugins/:: This directory contains the project's library files, including libsui_rust_sdk.dylib library to integrate with SUI network.
  2. SuiUnitySDK/:: The core SDK files and scripts.
  3. Samples/:: Includes sample scenes or scripts demonstrating how to use the SDK.
  4. TextMesh Pro/: This directory contains the TextMesh Pro package assets.

Features

General

  • Compatibility with main, dev, and test networks.
  • Integration with Sui blockchain using native libraries.
  • Cross-platform support (macOS, Windows, Linux).

SuiNFT.cs

  • Mint new NFTs.
  • Transfer NFTs to other addresses.
  • Retrieve wallet objects related to NFTs.
  • Conversion between raw and managed data structures for NFT objects.

SuiBCS.cs

  • 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.

SuiMultisig.cs

  • 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.

SuiTransactionBuilder.cs

  • 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.

SuiWallet.cs

  • 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.

Requirements

Platforms Unity Version Status
Mac Unity 2022 Fully Tested

Dependencies

Installation

Installation Guide

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:

Prerequisites

Project Setup

Run follow command to setting Environment before testing:

  1. 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
  1. Switch to devnet network:
    sui client switch --env devnet
  2. Check current network:
    sui client active-env

NOTE: The return should be devnet

  1. Get the active address:
    sui client active-address
  2. Request token:
    sui client faucet 

NOTE: Wait for 60s to get the tokens

  1. Check the gas coin objects for the active address:
    sui client gas

Install Unity-Sui-SDK

  1. Via 'Add package from git URL' in Unity Package Manager
  2. 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

Examples

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.

Network Building

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.

Build Testnet

To build the testnet environment:

bool success = SuiClient.BuildTestnet();
if (success)
{
    Debug.Log("Testnet built successfully.");
}
else
{
    Debug.LogError("Failed to build testnet.");
}
Build Devnet

To build the devnet environment:

bool success = SuiClient.BuildDevnet();
if (success)
{
    Debug.Log("Devnet built successfully.");
}
else
{
    Debug.LogError("Failed to build devnet.");
}
Build Mainnet

To build the mainnet environment:

bool success = SuiClient.BuildMainnet();
if (success)
{
    Debug.Log("Mainnet built successfully.");
}
else
{
    Debug.LogError("Failed to build mainnet.");
}

Wallet

The SuiWallet class provides various functionalities to manage wallets in your Unity project. Below are some examples of how touse the SuiWallet class.

Generate a New Wallet

To generate a new wallet with a specified key scheme and word length:

SuiWallet.WalletData newWallet = SuiWallet.GenerateWallet("ED25519", "12");
newWallet.Show();
Import Wallet from Private Key

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.");
}
Import Wallet from Mnemonic

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.");
}
List All Wallets

To list all wallets:

SuiWallet.WalletData[] wallets = SuiWallet.LoadWallets();
foreach (var wallet in wallets)
{
    wallet.Show();
}
Generate and Add New Key

To generate and add a new key to the wallet:

SuiWallet.GenerateAndAddNew();

Transactions

The SuiTransactionBuilder class allows you to create and manage transactions. Below are some examples of how to use the SuiTransactionBuilder class.

Create a New Transaction

To create a new transaction:

SuiTransactionBuilder.CreateBuilder();
Add a Move Call Command

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);
Add a Transfer Object Command

To add a transfer object command to the transaction:

SuiAgruments agreements = SuiTransactionBuilder.CreateArguments();
SuiAgruments recipient = SuiTransactionBuilder.CreateArguments();
SuiTransactionBuilder.AddTransferObjectCommand(agreements, recipient);
Execute the Transaction

To execute the transaction:

string result = SuiTransactionBuilder.ExecuteTransaction("sender_address", 1000);
Debug.Log(result);
Execute the Transaction with a Sponsor

To execute the transaction with a sponsor:

string result = SuiTransactionBuilder.ExecuteTransactionAllowSponser("sender_address", 1000, "sponsor_address");
Debug.Log(result);

Basic Serialization and Deserialization

The SuiBCS class provides methods for basic serialization and deserialization of Sui types. Below are some examples of how to use the SuiBCS class.

Serialize Data

To serialize data of a specific Sui type:

string data = "12345";
SuiPure serializedData = SuiBCS.BscBasic(SuiBCS.SuiType.U64, data);
IntPtr serializedPtr = serializedData.GetData();

Multisig Wallets

The SuiMultisig class provides functionalities to create and manage multisig wallets. Below are some examples of how to use the SuiMultisig class.

Create a Multisig Wallet

To create a new multisig wallet:

SuiMultisig.CreateMultisigWallet(new string[] { "address1", "address2", "address3" }, 2);
Create a Transaction from Multisig Wallet

To create a transaction from a multisig wallet:

SuiMultisig.CreateTransaction();
Sign and Execute a Multisig Transaction

To sign and execute a transaction using a multisig wallet:

string result = SuiMultisig.SignAndExecuteTransaction(SuiTransactionBuilder, "signer_address");
Debug.Log(result);

NFT Operations

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.

Mint a New NFT

To mint a new NFT:

string result = SuiNFT.Mint_NFT("sender_address", "NFT Name", "NFT Description", "NFT URI");
Debug.Log("Mint Result: " + result);
Transfer an NFT

To transfer an NFT to another address:

string result = SuiNFT.Transfer_NFT("sender_address", "nft_id", "recipient_address");
Debug.Log("Transfer Result: " + result);
Retrieve Wallet Objects

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);
}

License

This project is licensed under the Apache-2.0 License. Refer to the LICENSE.txt file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •