定制 sui-php/sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sui-php/sdk

最新稳定版本:0.1.1

Composer 安装命令:

composer require sui-php/sdk

包简介

SUI PHP SDK

README 文档

README

About

SUI PHP SDK is a PHP library that provides easy access to the SUI blockchain. This SDK allows PHP developers to interact with SUI blockchain nodes, create transactions, serialize and deserialize data using Binary Canonical Serialization (BCS), and manage accounts without writing low-level code. It is also fully implemented from the @mysten/sui (https://sdk.mystenlabs.com/typescript) TypeScript library. In other words, it is designed with the same structure there and you can easily find what you need in this library by examining the document in the link.

Key features:

  • Network communication with SUI nodes
  • BCS serialization and deserialization
  • Transaction building and signing
  • Account management

Installation

composer require sui-php/sdk

Example

require 'vendor/autoload.php';

use Sui\Utils;
use Sui\Client;
use Sui\Bcs\Bcs;
use Sui\Keypairs\Ed25519\Keypair;
use Sui\Transactions\Inputs;
use Sui\Transactions\Commands;
use Sui\Transactions\Transaction;
use Sui\Transactions\BuildTransactionOptions;

$client = new Client('https://fullnode.devnet.sui.io:443');

$coin = Bcs::struct('Coin', [
    'value' => Bcs::u64(),
    'owner' => Bcs::string(),
    'is_locked' => Bcs::bool(),
]);

$rustBcs = 'gNGxBWAAAAAOQmlnIFdhbGxldCBHdXkA';
$expected = [
    'owner' => 'Big Wallet Guy',
    'value' => '412412400000',
    'is_locked' => false,
];

$serialized = $coin->serialize($expected, ['initialSize' => 1, 'maxSize' => 1024]);
$parsed = $coin->fromBase64($rustBcs);

$ref = [
    'objectId' => str_pad(strval(mt_rand(0, 100000)), 64, '0'),
    'version' => strval(mt_rand(0, 10000)),
    'digest' => Utils::toBase58(json_decode('[
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
        1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
        2, 3, 4, 5, 6, 7, 8, 9, 1, 2
    ]'))
];

$keypair = Keypair::generate();
$tx = new Transaction(new BuildTransactionOptions($client));

$tx->setSender($keypair->getPublicKey()->toSuiAddress());
$tx->setGasPrice(5);
$tx->setGasBudget(100);
$tx->setGasPayment([$ref]);

$coin = $tx->splitCoins($tx->gas(), [100]);

$tx->add(Commands::mergeCoins($tx->gas(), [$coin, $tx->object(Inputs::objectRef(
    $ref['objectId'],
    $ref['digest'],
    $ref['version']
))]));

$tx->add(Commands::moveCall([
    'target' => '0x2::devnet_nft::mint',
    'typeArguments' => [],
    'arguments' => [
        $tx->pureFactory->string('foo'),
        $tx->pureFactory->string('bar'),
        $tx->pureFactory->string('baz'),
    ],
]));

$bytes = $tx->build();

$serializedSignature = $keypair->signTransaction($bytes);

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-25