1. Go to this page and download the library: Download sandermuller/solana-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/ */
sandermuller / solana-php-sdk example snippets
use SanderMuller\SolanaPhpSdk\Keypair;
$payer = Keypair::generate();
echo $payer->getPublicKey()->toBase58(), "\n";
// → e.g. 4uTYf8w...EPnL (this is your wallet address)
use SanderMuller\SolanaPhpSdk\DataObjects\GpaFilter;
use SanderMuller\SolanaPhpSdk\Programs\SplTokenProgram;
// All SPL Token accounts holding a specific mint (offset 0..32 = mint pubkey).
$rows = $connection->programAccounts(
programId: SplTokenProgram::TOKEN_PROGRAM_ID,
filters: [
GpaFilter::dataSize(165), // SPL Token Account = 165 bytes
GpaFilter::memcmp(0, $mintPublicKey), // mint at offset 0
],
);
foreach ($rows as $row) {
echo $row->pubkey->toBase58(), ' ', $row->account->lamports, "\n";
// $row->account->data is a base64-decoded Buffer
}
use SanderMuller\SolanaPhpSdk\Programs\MemoProgram;
$tx->addInstructions(
MemoProgram::build('order-id=42', signers: [$payer->getPublicKey()]),
);
use SanderMuller\SolanaPhpSdk\Util\PriorityFee;
[$limit, $price] = PriorityFee::buildInstructions(
connection: $connection,
computeUnitLimit: 200_000,
writableAccounts: [$payer->getPublicKey()], // tighter estimate
percentile: 0.75, // beat 75% of recent traffic
);
$tx = new Transaction(feePayer: $payer->getPublicKey());
$tx->addInstructions($limit, $price, /* your real instructions */);
use SanderMuller\SolanaPhpSdk\Programs\Token2022Program;
$program = new Token2022Program();
// 1. Allocate the mint account (system program), then queue extensions
// BEFORE InitializeMint — Token-2022 ordering rule.
$tx = TransactionBuilder::new()
->feePayer($payer->getPublicKey())
->recentBlockhash($connection->latestBlockhash())
->addInstructions(
// Allocate + assign owner via SystemProgram::createAccount (omitted)
$program->createInitializeNonTransferableMintInstruction($mint->getPublicKey()),
$program->createInitializeMintCloseAuthorityInstruction($mint->getPublicKey(), $payer->getPublicKey()),
$program->createInitializeTransferFeeConfigInstruction(
mint: $mint->getPublicKey(),
transferFeeConfigAuthority: $payer->getPublicKey(),
withdrawWithheldAuthority: $payer->getPublicKey(),
transferFeeBasisPoints: 250, // 2.5%
maximumFee: 1_000_000,
),
// Finally initialize the mint
$program->createInitializeMint2Instruction(
mint: $mint->getPublicKey(),
decimals: 6,
mintAuthority: $payer->getPublicKey(),
freezeAuthority: null,
),
)
->addSigner($payer)
->addSigner($mint)
->build();
// Enable both initializes the extension and turns the ToggleInstruction($tokenAccount, $owner->getPublicKey(), enable: true),
);
// Later — turn it off:
$program->createMemoTransferToggleInstruction($tokenAccount, $owner->getPublicKey(), enable: false);