multiplechain / solana-sdk
Solana PHP SDK
Requires
- php: ^8.1
- ext-sodium: *
- guzzlehttp/guzzle: ^7.3
- illuminate/http: ~8.0 || ~9.0
- illuminate/support: ^8.0 || ~9.0
- multiplechain/utils: ^0.1.3
- paragonie/sodium_compat: ^1.17
- stephenhill/base58: ^1.1
Requires (Dev)
- mockery/mockery: ^1.4
- phpstan/phpstan: ^1.11
- phpunit/php-code-coverage: ^10.1
- phpunit/phpunit: ^10.5
- slevomat/coding-standard: ^8.15
- squizlabs/php_codesniffer: ^3.10
- tightenco/tlint: ^5.0
This package is auto-updated.
Last update: 2024-11-05 06:20:11 UTC
README
NOTE: This package has been forked to be developed at MultipleChain to provide infrastructure for Solana. We are not adding it internally to MultipleChain because MultipleChain is an interface that covers all Blockchain networks. But for those who just want to do something for Solana, we aim to make something that covers everything in Solana/Web3.js.
Forked from: Sellix/solana-php-sdk
Simple PHP SDK for Solana.
Installation
You can install the package via composer:
composer require multiplechain/solana-sdk
Usage
Using the Solana simple client
You can use the Connection
class for convenient access to API methods. Some are defined in the code:
use MultipleChain\SolanaSDK\Connection; use MultipleChain\SolanaSDK\SolanaRpcClient; // Using a defined method $sdk = new Connection(new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT)); $accountInfo = $sdk->getAccountInfo('4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA'); var_dump($accountInfo);
For all the possible methods, see the API documentation.
Directly using the RPC client
The Connection
class is just a light convenience layer on top of the RPC client. You can, if you want, use the client directly, which allows you to work with the full Response
object:
use MultipleChain\SolanaSDK\SolanaRpcClient; $client = new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT); $accountInfoResponse = $client->call('getAccountInfo', ['4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA']); $accountInfoBody = $accountInfoResponse->json(); $accountInfoStatusCode = $accountInfoResponse->getStatusCode();
Transactions
Here is working example of sending a transfer instruction to the Solana blockchain:
$client = new SolanaRpcClient(SolanaRpcClient::DEVNET_ENDPOINT); $connection = new Connection($client); $fromPublicKey = KeyPair::fromSecretKey([...]); $toPublicKey = new PublicKey('J3dxNj7nDRRqRRXuEMynDG57DkZK4jYRuv3Garmb1i99'); $instruction = SystemProgram::transfer( $fromPublicKey->getPublicKey(), $toPublicKey, 6 ); $transaction = new Transaction(null, null, $fromPublicKey->getPublicKey()); $transaction->add($instruction); $txHash = $connection->sendTransaction($transaction, $fromPublicKey);
Note: This project is in alpha, the code to generate instructions is still being worked on $instruction = SystemProgram::abc()
Roadmap
- Borsh serialize and deserialize.
- Improved documentation.
- Build out more of the Connection, SystemProgram, TokenProgram, MetaplexProgram classes.
- Improve abstractions around working with binary data.
- Optimizations:
- Leverage PHP more.
- Better cache
$recentBlockhash
when sending transactions.
- Suggestions? Open an issue or PR :D
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please create an issue in this repository.
Credits
- Matt Stauffer (Original creator)
- Zach Vander Velden (Metadata wizard)
- Halil Beycan (Maintainer)
- All Contributors
License
The MIT License (MIT). Please see License File for more information.