Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
NotificationsYou must be signed in to change notification settings

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

PlatformsUnity VersionStatus
MacUnity 2022Fully 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 fromhttps://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

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.

Build Testnet

To build the testnet environment:

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

To build the devnet environment:

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

To build the mainnet environment:

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

Wallet

TheSuiWallet class provides various functionalities to manage wallets in your Unity project. Below are some examples of how touse theSuiWallet class.

Generate a New Wallet

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

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

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

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

To list all wallets:

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

To generate and add a new key to the wallet:

SuiWallet.GenerateAndAddNew();

Transactions

TheSuiTransactionBuilder class allows you to create and manage transactions. Below are some examples of how to use theSuiTransactionBuilder 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:

SuiTypeTagstypeTags=SuiTransactionBuilder.CreateTypeTags();SuiAgrumentsarguments=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:

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

To execute the transaction:

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

To execute the transaction with a sponsor:

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

Basic Serialization and Deserialization

TheSuiBCS class provides methods for basic serialization and deserialization of Sui types. Below are some examples of how to use theSuiBCS class.

Serialize Data

To serialize data of a specific Sui type:

stringdata="12345";SuiPureserializedData=SuiBCS.BscBasic(SuiBCS.SuiType.U64,data);IntPtrserializedPtr=serializedData.GetData();

Multisig Wallets

TheSuiMultisig class provides functionalities to create and manage multisig wallets. Below are some examples of how to use theSuiMultisig class.

Create a Multisig Wallet

To create a new multisig wallet:

SuiMultisig.CreateMultisigWallet(newstring[]{"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:

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

NFT Operations

TheSuiNFT class provides functionalities to mint, transfer, and retrieve NFT-related wallet objects. Below are some examples of how to use theSuiNFT class.

Mint a New NFT

To mint a new NFT:

stringresult=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:

stringresult=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(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);}

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

[8]ページ先頭

©2009-2025 Movatter.jp