PHP code example of sui-php / sdk
1. Go to this page and download the library: Download sui-php/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/ */
sui-php / sdk example snippets
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);
bash
composer