Skip to content

Latest commit

 

History

History
391 lines (266 loc) · 9.73 KB

README.md

File metadata and controls

391 lines (266 loc) · 9.73 KB

Sui-Godo-SDKLogo

Sui-Godot-SDK

Sui-Godot-SDK is a package to help developers integrate Sui blockchain technology into their godot projects.

Project Structure

  1. project_demo/: This directory contains the example use.
  2. resources/: A place for various resources needed for the project, like images, data files, or other assets.
  3. modules/: This directory contains the project's source code.

Features

General

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

sui_nfts.cpp

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

sui_multisig.cpp

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

sui_builder.cpp

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

sui_wallet.cpp

  • 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 Godot Version Status
Mac / Linux / Windows Godot 4.3 Fully Tested

Dependencies

Installation

Installation Guide

This guide provides step-by-step instructions for installing and setting up on macOS / Linus / Windows 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 don't have DevNet, please run CMD :

    sui client new-env --alias devnet --rpc https://fullnode.devnet.sui.io:443
  2. Switch to devnet network:

    sui client switch --env devnet
  3. Check current network:

    sui client active-env

    NOTE: The return should be devnet

  4. Get the active address:

    sui client active-address
  5. Request token:

    sui client faucet

    NOTE: Wait for 60s to get the tokens

  6. Check the gas coin objects for the active address:

    sui client gas
  7. Build Project:

    • In Sui-Godot-SDK directory run CMD:
    git clone -b 4.3 https://github.com/godotengine/godot
    • Change working directory to godot:
    cd godot
    • Build project cmd:
    scons custom_modules=../modules

Install Sui-Godot-SDK

  • Get godot engine: In Sui-Godot-SDK directory run CMD:

    git clone -b 4.3 https://github.com/godotengine/godot
  • Compile the engine:

    cd godot
    scons custom_modules=../modules

Sui-Godot-SDK can integrate into your own godot projects.

You can custom your project_demo and run below built file in directory to check your source code.

./godot/bin/<godot_binary>

NOTE:

  • If you are running on Windows environment, please copy file sui_rust_sdk.dll at modules/sui_sdk/libs directory into godot/bin directory

  • If you are running on Linux environment, please run cmd below to set environment variable:

    source ./.bashrc

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.

Initialize the SDK

var suiSDK = SuiSDK.new()

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:

var newWallet = suiSDK.generateWallet("ED25519", "12")
print(wallet.get_address())
print(wallet.get_mnemonic())
print(wallet.get_public_base64_key())
print(wallet.get_private_key())
print(wallet.get_key_scheme())
Import Wallet from Private Key

To import a wallet using a private key:

var importResult = suiSDK.importFromPrivateKey("your_private_key_here")
if importResult.get_status() == 0:
   print("Import wallet " + importResult.get_address() + " successfully")
else:
   print(importResult.get_error())
Import Wallet from Mnemonic

To import a wallet using a mnemonic phrase:

var importResult = suiSDK.importFromMnemonic("your_mnemonic_phrase_here")
if importResult.get_status() == 0:
   print("Import wallet " + importResult.get_address() + " successfully")
else:
   print(importResult.get_error())
List All Wallets

To list all wallets:

var wallets = suiSDK.getWallets()
for wallet in wallets:
   print(wallet.get_address())
   print(wallet.get_mnemonic())
   print(wallet.get_public_base64_key())
   print(wallet.get_private_key())
   print(wallet.get_key_scheme())
Generate and Add New Key

To generate and add a new key to the wallet:

var wallet = sdk.generateAndAddKey()

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:

var builder = SuiProgrammableTransactionBuilder.new()
Add a Move Call Command

To add a move call command to the transaction:

var arguments = SuiArguments.new()
var typeTag = SuiTypeTags.new()
suiSDK.addMoveCallCommand(builder, "package_id", "module_name", "function_name", typeTag, arguments)
Add a Transfer Object Command

To add a transfer object command to the transaction:

var agreements = SuiArguments.new()
suiSDK.addArgumentResult(agreements, 0)
var recipient = SuiArguments.new()
var recipientBscBasic = SuiBSCBasic.new()
recipientBscBasic.BSCBasic("address", "recipient_address")

suiSDK.addTransferObjectCommand(builder, agreements, recipient)
Execute the Transaction

To execute the transaction:

var gas = 0.005 * 10**9
var result = suiSDK.executeTransaction(builder, "sender_address", gas)
print(result)

Basic Serialization and Deserialization

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

Serialize Data

To serialize data of a specific Sui type:

var amount = 1;
var amountBscBasic = SuiBSCBasic.new()
amountBscBasic.BSCBasic("u64", str(int(amount)*10**9))

Multisig Wallets

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

Create a Multisig Wallet

To create a new multisig wallet:

var address1 = "wallet_address_1"
var address2 = "wallet_address_2"
var address3 = "wallet_address_3"
var addresses = [address1, address2, address3]
var weights = [1, 1, 2]
var multiSig = suiSDK.getOrCreateMultisig(addresses, weights, 3)
Create a Transaction from Multisig Wallet

To create a transaction from a multisig wallet:

var amount = 1 *10**9
var txBytes = suiSDK.createTransaction("wallet_address", "wallet_address", amount)
Sign and Execute a Multisig Transaction

To sign and execute a transaction using a multisig wallet:

var address1 = "wallet_address_1"
var address2 = "wallet_address_2"
var address3 = "wallet_address_3"
var signer_addresses = [address2, address3]
var message = suiSDK.signAndExecuteTransaction(multiSig, txBytes, signer_addresses)
print(message)

NFT Operations

The sui_nfts provides functionalities to mint, transfer, and retrieve NFT-related wallet objects. Below are some examples of how to use the sui_nfts.

Mint a New NFT

To mint a new NFT:

var message = suiSDK.mintNft("package_id", "sender_address", "NFT Name", "NFT Description", "NFT URI")
print(message)
Transfer an NFT

To transfer an NFT to another address:

var message = suiSDK.transferNft("package_id", "sender_address", "nft_id", "recipient_address")
print(message)
Retrieve Wallet Objects

To retrieve wallet objects related to NFTs:

var nfts = suiSDK.getWalletObjects("wallet_address", "object_type")

License

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