mclever/larasui-sdk

A Laravel SDK for interacting with the SUI blockchain.

v1.0.10 2025-03-01 08:52 UTC

This package is auto-updated.

Last update: 2025-06-12 03:56:41 UTC


README

A comprehensive, Laravel-friendly SDK for interacting with the Sui blockchain using Move smart contracts. Built for developers to seamlessly integrate Sui’s features—token creation, NFT minting, staking, transaction batching, and more—into their Laravel applications.

License Latest Version on Packagist

Requirements

  • PHP: ^8.0

  • Laravel: ^10.0

  • Frontend wallet integration (e.g., @mysten/sui.js) for signing/executing transactions.

Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. API Reference
  5. Contributing
  6. License

Installation

Install the package via Composer:

composer require mclever/larasui-sdk

Publish the configuration file:

php artisan vendor:publish --tag="config"

This will create a sui.php configuration file in your config directory.

Configuration

Update the config/sui.php file with your SUI RPC URL:

return [
    'rpc_url' => env('SUI_RPC_URL', 'https://fullnode.devnet.sui.io:443'),
];

You can also set the SUI_RPC_URL in your .env file:

SUI_RPC_URL=https://fullnode.devnet.sui.io:443

Usage

Connecting to a Wallet

To connect to a wallet, use the connectWallet method. This method prepares the wallet connection, but the actual connection must be completed by the frontend (e.g., using @mysten/sui.js).

use Mclever\LarasuiSdk\Facades\Sui;

$walletAddress = Sui::connectWallet();

Fetching Balances

Fetch the balance of an address for a specific coin type (default is SUI):

$balance = Sui::getBalance('0xYourAddress');
echo "Balance: {$balance} SUI";

Creating Tokens

Create a new fungible token:

$txDigest = Sui::createToken(
    'MyToken',
    'MTK',
    6, // Decimals
    '0xYourAddress',
    1000000, // Initial supply
    10000 // Gas budget
);
echo "Token creation transaction digest: {$txDigest}";

Creating NFTs

Create a new NFT:

$txDigest = Sui::createNFT(
    'MyNFT',
    'A unique NFT',
    'https://example.com/nft-metadata.json',
    '0xYourAddress',
    10000 // Gas budget
);
echo "NFT creation transaction digest: {$txDigest}";

Executing Move Calls

Execute a Move call:

$txDigest = Sui::executeMoveCall(
    '0xPackageId',
    'module_name',
    'function_name',
    [], // Type arguments
    ['arg1', 'arg2'], // Function arguments
    '0xYourAddress',
    10000 // Gas budget
);
echo "Move call transaction digest: {$txDigest}";

Transferring Assets

Transfer coins or objects to another address:

$txDigest = Sui::transfer(
    '0xYourAddress',
    '0xRecipientAddress',
    '0xObjectId',
    10000 // Gas budget
);
echo "Transfer transaction digest: {$txDigest}";

Staking SUI

Stake SUI to a validator:

$txDigest = Sui::stakeSui(
    '0xYourAddress',
    '0xValidatorAddress',
    '0xCoinId',
    1000000000, // Amount to stake
    10000 // Gas budget
);
echo "Staking transaction digest: {$txDigest}";

Fetching Transaction Details

Get details for a transaction by its digest:

$transaction = Sui::getTransaction('0xTransactionDigest');
print_r($transaction);

Fetching Events

Fetch recent events of a specific type:

$events = Sui::getEvents('0xPackage::module::Event', 10);
print_r($events);

API Reference

SuiClient Methods

  • connectWallet(): Prepares wallet connection.
  • getBalance(string $address, ?string $coinType = '0x2::sui::SUI'): Fetches the balance of an address.
  • createToken(string $name, string $symbol, int $decimals, string $sender, int $initialSupply, int $gasBudget = 10000): Creates a new fungible token.
  • createNFT(string $name, string $description, string $uri, string $sender, int $gasBudget = 10000): Creates a new NFT.
  • executeMoveCall(string $packageId, string $module, string $function, array $typeArgs, array $args, string $sender, ?int $gasBudget = null): Executes a Move call.
  • transfer(string $sender, string $recipient, string $objectId, int $gasBudget = 10000): Transfers coins or objects.
  • stakeSui(string $sender, string $validatorAddress, string $coinId, int $amount, ?int $gasBudget = null): Stakes SUI to a validator.
  • getTransaction(string $txDigest): Fetches transaction details.
  • getEvents(string $eventType, int $limit = 10): Fetches recent events.
  • getCoinMetadata(string $coinType): Fetches metadata for a coin type.

For a full list of methods, refer to the SuiClient class.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Built by Mr clever with for the Sui and Laravel communities.

Support

For questions or issues, please open an issue on GitHub.

Happy coding! 🚀