Unreal-Sui-SDK is a sample example to help developers integrate Sui blockchain technology into their C++ and Unreal projects.
- Project Layout
- Features
- Requirements
- Dependencies
- Installation
- Using Unreal-Sui-SDK
- Using Unreal-Sui-SDK with Blueprint
- Examples
- License
Config/
:: This directory contains the project's configuration files, including INI files used to set various project parameters .Content/
:: This directory contains all the project's content assets.Lib/
:: This directory contains the libsui_rust_sdk.dylib library and header files to use the functions in the library.Resource/
:: A place for various resources needed for the project, like images, data files, or other assets.Source/
: This directory contains the project's C++ source code.
- 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 | Unreal Version | Installation | Status |
---|---|---|---|
Mac / Linux | Unity engine 5.4 | 3rd lib build config | 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 Envỉroment befor 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
Unreal-Sui-SDK can integrate into your own Unreal projects. We have two options to run the project:
-
Open the Unreal project directly through the SuisdkUnreal.uproject file and then click the Run icon to test.
-
Open the project using Visual Studio Code, build the source code, and run the test.
For option 2 you need define Build.cs to integration libsui_rust_sdk.dylib library with Unreal engine. Here is an example:
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.IO;
using System;
public class SuisdkUnreal : ModuleRules
{
public SuisdkUnreal(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Json", "JsonUtilities", "HTTP", "ImageWrapper" });
PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
if (Target.Platform == UnrealTargetPlatform.Mac)
{
string unreal_sui_sdk_LibPath = Path.Combine(ModuleDirectory, "../../Lib/", "libsui_rust_sdk.dylib");
string destinationDirectory = Target.ProjectFile.Directory.FullName;
PublicAdditionalLibraries.Add(unreal_sui_sdk_LibPath);
PublicIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "../../Lib/") });
PublicIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "../../../") });
}
CppStandard = CppStandardVersion.Cpp17;
}
}
To import a wallet using a private key:
ImportResult *result = import_from_private_key(PRIVATE_KEY_BASE64);
printf("Status: %d\n", result->status);
printf("Address: %s\n", result->address);
printf("Error: %s\n", result->error);
To import a wallet using a mnemonic:
ImportResult *result = import_from_mnemonic(SENDER_MNEMONIC, "ED25519", SENDER_MNEMONIC_ALIAS);
printf("Status: %d\n", result->status);
printf("Address: %s\n", result->address);
printf("Error: %s\n", result->error);
To get saved wallets:
WalletList wallet_list = get_wallets();
To get saved wallet from address:
Wallet *wallet = get_wallet_from_address(ADDRESS);
To generate wallet using key scheme and word length:
Wallet *wallet = generate_wallet("ed25519", "word12");
To generate random and save wallet:
Wallet *wallet = generate_and_add_key();
To request tokens from faucet:
const char *response = request_tokens_from_faucet(FAUCET_ADDRESS);
unsigned long long amount = 1000000000;
const char *result = programmable_transaction(SENDER_ADDRESS, RECIPIENT_ADDRESS, amount);
assert(result != NULL);
printf("Result: %s\n", result);
free((void *)result);
unsigned long long amount = 5400000000;
const char *result = programmable_transaction_allow_sponser(SENDER_ADDRESS, RECIPIENT_ADDRESS, amount, SPONSER_ADDRESS);
assert(result != NULL);
printf("Result: %s\n", result);
free((void *)result);
// Create a new builder
CProgrammableTransactionBuilder *builder = create_builder();
assert(builder != NULL);
//
CArguments *coin = create_arguments();
add_argument_gas_coin(coin);
CArguments *amount = create_arguments();
make_pure(builder, amount, bsc_basic("u64", "1000000000000"));
add_split_coins_command(builder, coin, amount);
// Add a transfer object command
CArguments *agrument = create_arguments();
add_argument_result(agrument, 0);
CArguments *recipient = create_arguments();
make_pure(builder, recipient, bsc_basic("address", RECIPIENT_ADDRESS));
add_transfer_object_command(builder, agrument, recipient);
// Execute the builder
const char *result = execute_transaction(builder, SENDER_ADDRESS, 5000000);
assert(result != NULL);
printf("Result: %s\n", result);
// Step 1: Create a multisig
const char *addresses[] = {"0x013c740d731b06bb7447316e7b43ea6120d808d07cd0a8a0c6f391930bd449dd", "0x2107184d961804e3cbeef48106a7384d11d90f5a050fde0709da8e079450b824", "0x3d8c53148ba895d5aaa4a604af9864dd041fb409977fdfacc313f296f36faa77"};
CStringArray addr_array = {addresses, 3};
unsigned char weights_data[] = {1, 1, 1};
CU8Array weights = {weights_data, 3, NULL};
uint16_t threshold = 2;
// Test get_or_create_multisig
CMultiSig multisig = get_or_create_multisig(addr_array, weights, threshold);
if (multisig.error)
{
printf("Error creating multisig: %s\n", multisig.error);
}
else
{
printf("Multisig Address: %s\n", multisig.address);
printf("Multisig Bytes: ");
print_hex(multisig.bytes.data, multisig.bytes.len);
}
// Step 2: Create a transaction
const char *from_address = "0x5e4f2cce89e8c5f634b4692fdad3e1345b88aa90546ccaa417fd8a5b0591a21c";
const char *to_address = "0x7bee59cf2c25539bb267b7d26ae8722f1dfe5112949727648f7b17de0ea72432";
uint64_t amount = 1000; // Sample transfer amount
CU8Array tx = create_transaction(from_address, to_address, amount);
if (tx.error)
{
printf("Error creating transaction: %s\n", tx.error);
}
else
{
printf("Transaction bytes: ");
print_hex(tx.data, tx.len);
}
// Step 3: Sign and execute the multisig transaction
const char *result = sign_and_execute_transaction_miltisig(multisig.bytes, tx, addr_array);
if (result)
{
printf("Error signing and executing transaction: %s\n", result);
}
else
{
printf("Transaction executed successfully.\n");
}
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.
This project is licensed under the Apache-2.0 License. Refer to the LICENSE.txt file for details.