Hello, I am one of the developers and maintainers of the Soneso Stellar iOS and Flutter SDK.
And today, I would like to present our new Soneso Stellar PHP SDK.
It is a SDK for PHP developers, that facilitates integration with the Stellar Horizon API server and submission of Stellar transactions. It is now ready for beta testing.
If you are a PHP developer and interested in using it for your app or wallet, please check it out.
Here are some examples of typical usage:
- Keypair generation
// create a completely new and unique pair of keys.
$keyPair = KeyPair::random();
print($keyPair->getAccountId());
// GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB
print($keyPair->getSecretSeed());
// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
- Check Account
$accountId = "GCQHNQR2VM5OPXSTWZSF7ISDLE5XZRF73LNU6EOZXFQG2IJFU4WB7VFY";
// Request the account data.
$account = $sdk->requestAccount($accountId);
// You can check the `balance`, `sequence`, `flags`, `signers`, `data` etc.
foreach ($account->getBalances() as $balance) {
switch ($balance->getAssetType()) {
case Asset::TYPE_NATIVE:
printf (PHP_EOL."Balance: %s XLM", $balance->getBalance() );
break;
default:
printf(PHP_EOL."Balance: %s %s Issuer: %s",
$balance->getBalance(), $balance->getAssetCode(),
$balance->getAssetIssuer());
}
}
print(PHP_EOL."Sequence number: ".$account->getSequenceNumber());
foreach ($account->getSigners() as $signer) {
print(PHP_EOL."Signer public key: ".$signer->getKey());
}
- Send Payment
$senderKeyPair = KeyPair::fromSeed("SA52PD5FN425CUONRMMX2CY5HB6I473A5OYNIVU67INROUZ6W4SPHXZB");
$destination = "GCRFFUKMUWWBRIA6ABRDFL5NKO6CKDB2IOX7MOS2TRLXNXQD255Z2MYG";
// Load sender account data from the stellar network.
$sender = $sdk->requestAccount($senderKeyPair->getAccountId());
// Build the transaction to send 100 XLM native payment from sender to destination
$paymentOperation = (new PaymentOperationBuilder($destination,Asset::native(), "100"))->build();
$transaction = (new TransactionBuilder($sender))->addOperation($paymentOperation)->build();
// Sign the transaction with the sender's key pair.
$transaction->sign($senderKeyPair, Network::testnet());
// Submit the transaction to the stellar network.
$response = $sdk->submitTransaction($transaction);
if ($response->isSuccessful()) {
print(PHP_EOL."Payment sent");
}
- Check payments
You can check the payments connected to an account:
$accountId = $account->getAccountId();
$operationsPage = $sdk->payments()->forAccount($accountId)->order("desc")->execute();
foreach ($operationsPage->getOperations() as $payment) {
if ($payment->isTransactionSuccessful()) {
print(PHP_EOL."Transaction hash: ".$payment->getTransactionHash());
}
}
You can use:limit
, order
, and cursor
to customize the query. Get the most recent payments for accounts, ledgers and transactions.
GitHub Repo: https://github.com/Soneso/stellar-php-sdk
Installation: https://github.com/Soneso/stellar-php-sdk#installation
Quick Start: https://github.com/Soneso/stellar-php-sdk#quick-start
Examples: https://github.com/Soneso/stellar-php-sdk/tree/main/examples
Testing feedback and all suggestions are welcome. You can create issues here: add issue