PHP code example of soneso / stellar-php-sdk

1. Go to this page and download the library: Download soneso/stellar-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/ */

    

soneso / stellar-php-sdk example snippets


$payment = (new PaymentOperationBuilder($receiverId, Asset::native(), '100'))->build();
$tx = (new TransactionBuilder($account))->addOperation($payment)->build();
$tx->sign($senderKeyPair, Network::testnet());
$sdk->submitTransaction($tx);

$asset = Asset::createNonNativeAsset('USDC', $issuerAccountId);
$trustOp = (new ChangeTrustOperationBuilder($asset))->build();
$tx = (new TransactionBuilder($account))->addOperation($trustOp)->build();
$tx->sign($accountKeyPair, Network::testnet());
$sdk->submitTransaction($tx);

$client = SorobanClient::forClientOptions(new ClientOptions(
    sourceAccountKeyPair: $keyPair,
    contractId: 'CABC...',
    network: Network::testnet(),
    rpcUrl: 'https://soroban-testnet.stellar.org'
));
$result = $client->invokeMethod('hello', [XdrSCVal::forSymbol('World')]);
bash
composer