- Notifications
You must be signed in to change notification settings - Fork0
VAR-META-Tech/Unity-Sui-SDK
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 Suihttps://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 fromhttps://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.
TheSuiClient
class provides methods to build and switch between different Sui networks (testnet, devnet, mainnet). Below are some examples of how to use theSuiClient
class.
To build the testnet environment:
boolsuccess=SuiClient.BuildTestnet();if(success){Debug.Log("Testnet built successfully.");}else{Debug.LogError("Failed to build testnet.");}
To build the devnet environment:
boolsuccess=SuiClient.BuildDevnet();if(success){Debug.Log("Devnet built successfully.");}else{Debug.LogError("Failed to build devnet.");}
To build the mainnet environment:
boolsuccess=SuiClient.BuildMainnet();if(success){Debug.Log("Mainnet built successfully.");}else{Debug.LogError("Failed to build mainnet.");}
TheSuiWallet
class provides various functionalities to manage wallets in your Unity project. Below are some examples of how touse theSuiWallet
class.
To generate a new wallet with a specified key scheme and word length:
SuiWallet.WalletDatanewWallet=SuiWallet.GenerateWallet("ED25519","12");newWallet.Show();
To import a wallet using a private key:
boolsuccess=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:
boolsuccess=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(varwalletinwallets){wallet.Show();}
To generate and add a new key to the wallet:
SuiWallet.GenerateAndAddNew();
TheSuiTransactionBuilder
class allows you to create and manage transactions. Below are some examples of how to use theSuiTransactionBuilder
class.
To create a new transaction:
SuiTransactionBuilder.CreateBuilder();
To add a move call command to the transaction:
SuiTypeTagstypeTags=SuiTransactionBuilder.CreateTypeTags();SuiAgrumentsarguments=SuiTransactionBuilder.CreateArguments();SuiTransactionBuilder.AddMoveCallCommand("package_id","module_name","function_name",typeTags,arguments);
To add a transfer object command to the transaction:
SuiAgrumentsagreements=SuiTransactionBuilder.CreateArguments();SuiAgrumentsrecipient=SuiTransactionBuilder.CreateArguments();SuiTransactionBuilder.AddTransferObjectCommand(agreements,recipient);
To execute the transaction:
stringresult=SuiTransactionBuilder.ExecuteTransaction("sender_address",1000);Debug.Log(result);
To execute the transaction with a sponsor:
stringresult=SuiTransactionBuilder.ExecuteTransactionAllowSponser("sender_address",1000,"sponsor_address");Debug.Log(result);
TheSuiBCS
class provides methods for basic serialization and deserialization of Sui types. Below are some examples of how to use theSuiBCS
class.
To serialize data of a specific Sui type:
stringdata="12345";SuiPureserializedData=SuiBCS.BscBasic(SuiBCS.SuiType.U64,data);IntPtrserializedPtr=serializedData.GetData();
TheSuiMultisig
class provides functionalities to create and manage multisig wallets. Below are some examples of how to use theSuiMultisig
class.
To create a new multisig wallet:
SuiMultisig.CreateMultisigWallet(newstring[]{"address1","address2","address3"},2);
To create a transaction from a multisig wallet:
SuiMultisig.CreateTransaction();
To sign and execute a transaction using a multisig wallet:
stringresult=SuiMultisig.SignAndExecuteTransaction(SuiTransactionBuilder,"signer_address");Debug.Log(result);
TheSuiNFT
class provides functionalities to mint, transfer, and retrieve NFT-related wallet objects. Below are some examples of how to use theSuiNFT
class.
To mint a new NFT:
stringresult=SuiNFT.Mint_NFT("sender_address","NFT Name","NFT Description","NFT URI");Debug.Log("Mint Result: "+result);
To transfer an NFT to another address:
stringresult=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(varobjinwalletObjects){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.