1. Go to this page and download the library: Download inodrahq/sui-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inodrahq / sui-sdk example snippets
use Inodrahq\SuiSdk\Wallet;
use Inodrahq\SuiSdk\SuiClient;
// Create a wallet
$wallet = new Wallet(); // random keypair
echo $wallet->getAddress(); // 0x...
// Or import from bech32 private key
$wallet = new Wallet('suiprivkey1...');
// Or from a mnemonic
$wallet = Wallet::fromMnemonic('abandon abandon abandon ...');
// Connect to testnet (JSON-RPC)
$client = SuiClient::forNetwork('testnet');
// Connect to testnet (gRPC --
use Inodrahq\SuiSdk\Transaction;
$tx = new Transaction($client);
$tx->setSender($wallet->getAddress());
// Gas price, budget, and coins are resolved automatically
$coin = $tx->splitCoins($tx->gas(), [$tx->pure('u64', '1000000000')]);
$tx->transferObjects([$coin], $tx->pure('address', $recipient));
// Build, sign, and execute in one call
$result = $tx->execute($wallet);
echo $result->digest;
// Automatically fetches object data and determines shared vs owned
$obj = $tx->object('0x5');
$tx->moveCall('0x3::sui_system::request_add_stake', [], [
$obj,
$coin,
$tx->pure('address', $validatorAddress),
]);
use Inodrahq\SuiSdk\Wallet;
// Ed25519 (default)
$wallet = new Wallet('suiprivkey1...');
// Secp256k1 -- auto-detected from key encoding
$wallet = new Wallet('suiprivkey1...');
// Secp256r1 -- auto-detected from key encoding
$wallet = new Wallet('suiprivkey1...');
// All wallets share the same API
$wallet->getAddress(); // 0x-prefixed Sui address
$wallet->sign($txData); // returns base64 signature
$wallet->signPersonalMessage('Hello, Sui!');
use Inodrahq\SuiSdk\Crypto\MultiSig\MultiSigPublicKey;
$msig = new MultiSigPublicKey([$pk1, $pk2, $pk3], [1, 1, 1], 2);
$address = $msig->toSuiAddress();
$combinedSig = $msig->combineSignatures([$sig1, $sig2]);
use Inodrahq\SuiSdk\Crypto\ZkLogin\ZkLoginAddress;
$address = ZkLoginAddress::fromJwtClaims($iss, $aud, $sub, $salt);
use Inodrahq\SuiSdk\Crypto\Passkey\PasskeyAuthenticator;
use Inodrahq\SuiSdk\Bcs\ObjectArg;
use Inodrahq\SuiSdk\Bcs\SuiAddress;
use Inodrahq\SuiSdk\Bcs\U64;
// Owned or immutable object
$arg = $builder->addObjectInput(ObjectArg::immOrOwnedObject($objectRef));
// Shared object (e.g., SuiSystemState at 0x5)
$arg = $builder->addObjectInput(ObjectArg::sharedObject(
new SuiAddress('0x5'), // object ID
new U64(1), // initial shared version
true, // mutable
));
// Receiving object
$arg = $builder->addObjectInput(ObjectArg::receiving($objectRef));
use Inodrahq\SuiSdk\PaginatedResponse;
// All paginated methods return PaginatedResponse
$page = $client->getCoins($owner);
echo $page->count(); // number of items
echo $page->hasNextPage; // bool
echo $page->nextCursor; // cursor for next page
// Iterate through all pages
foreach ($client->iterateCoins($owner) as $page) {
foreach ($page->data as $coin) {
echo $coin->coinObjectId . "\n";
}
}
use Inodrahq\SuiSdk\Crypto\Verifier;
// Verify a transaction signature
$isValid = Verifier::verifyTransactionSignature($signature, $txBytes);
// Verify a personal message signature
$isValid = Verifier::verifyPersonalMessage($signature, $message);
// Extract info from a signature
$publicKey = Verifier::extractPublicKey($signature); // hex
$address = Verifier::extractAddress($signature); // 0x...
use Inodrahq\SuiSdk\SuiClient;
use Inodrahq\SuiSdk\Transport\JsonRpcTransport;
// Using network preset
$client = SuiClient::forNetwork('mainnet');
// Custom endpoint with headers
$client = new SuiClient(new JsonRpcTransport('https://fullnode.mainnet.sui.io:443', [
'x-api-key' => 'your-key',
]));
use Inodrahq\SuiSdk\SuiClient;
use Inodrahq\SuiSdk\Transport\GrpcTransport;
// Using network preset
$client = SuiClient::forNetworkGrpc('testnet');
// Custom endpoint
$client = new SuiClient(new GrpcTransport('fullnode.mainnet.sui.io:443'));
// All methods work the same as JSON-RPC
$balance = $client->getBalance($address);
$result = $client->transferSui($wallet, $recipient, '1000000000');
$moduleBytes = file_get_contents('build/MyPackage/bytecode_modules/my_module.mv');
$dep1 = new SuiAddress('0x1'); // MoveStdlib
$dep2 = new SuiAddress('0x2'); // Sui Framework
$builder = new TransactionBuilder();
$builder->setSender($wallet->getAddress());
$upgradeCap = $builder->publish([$moduleBytes], [$dep1, $dep2]);
$sender = $builder->addPureAddress($wallet->getAddress());
$builder->transferObjects([$upgradeCap], $sender);
$builder->setGasBudget(100_000_000);
$result = $client->signAndExecuteTransaction($builder->build(), $wallet);
// Using the auto-resolving Transaction builder
$tx = new Transaction($client);
$tx->setSender($wallet->getAddress());
$amount = $tx->pure('u64', '1000000000');
$coin = $tx->splitCoins($tx->gas(), [$amount]);
$tx->moveCall('0x3::sui_system::request_add_stake', [], [
$tx->object('0x5'), // SuiSystemState (auto-resolved as shared)
$coin,
$tx->pure('address', $validatorAddress),
]);
$result = $tx->execute($wallet);