{"id":20923415,"url":"https://github.com/attestto-com/solana-php-sdk","last_synced_at":"2025-04-05T19:09:08.568Z","repository":{"id":235590426,"uuid":"790976180","full_name":"Attestto-com/solana-php-sdk","owner":"Attestto-com","description":"Simple PHP SDK for interacting with Transactions, Signatures, Borsh Serialization/Deserialization and RPCs","archived":false,"fork":false,"pushed_at":"2025-01-08T21:08:55.000Z","size":1297,"stargazers_count":40,"open_issues_count":11,"forks_count":23,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T19:09:03.294Z","etag":null,"topics":["blockchain-technology","did","laravel-11","php-library","php8","solana","spl-token"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Attestto-com.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-23T21:41:16.000Z","updated_at":"2025-04-02T13:19:21.000Z","dependencies_parsed_at":"2025-01-15T21:10:20.902Z","dependency_job_id":"dfedf13e-3a2e-4799-84ce-50cbe121a2b8","html_url":"https://github.com/Attestto-com/solana-php-sdk","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":"0.017857142857142905","last_synced_commit":"7628d7dadfde449d01d2b0b640b39ef47b9a4334"},"previous_names":["attestto-com/solana-php-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attestto-com%2Fsolana-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attestto-com%2Fsolana-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attestto-com%2Fsolana-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attestto-com%2Fsolana-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Attestto-com","download_url":"https://codeload.github.com/Attestto-com/solana-php-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386263,"owners_count":20930618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain-technology","did","laravel-11","php-library","php8","solana","spl-token"],"created_at":"2024-11-18T20:15:39.497Z","updated_at":"2025-04-05T19:09:08.533Z","avatar_url":"https://github.com/Attestto-com.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solana PHP SDK\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/attestto/solana-php-sdk.svg?style=flat-square)](https://packagist.org/packages/attestto/solana-php-sdk)\n[![GitHub Tests Action Status](https://github.com/Attestto-com/solana-php-sdk/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/Attestto-com/solana-php-sdk/actions/workflows/run-tests.yml)\n[![Coverage (CodeCov)](https://codecov.io/github/Attestto-com/solana-php-sdk/graph/badge.svg?token=M12LECZ9QE)](https://codecov.io/github/Attestto-com/solana-php-sdk)\n\n```js\n    ____  __  ______     _____ ____  __    ___    _   _____       _____ ____  __ __\n   / __ \\/ / / / __ \\   / ___// __ \\/ /   /   |  / | / /   |     / ___// __ \\/ //_/\n  / /_/ / /_/ / /_/ /   \\__ \\/ / / / /   / /| | /  |/ / /| |     \\__ \\/ / / / ,\u003c   \n / ____/ __  / ____/   ___/ / /_/ / /___/ ___ |/ /|  / ___ |    ___/ / /_/ / /| |  \n/_/   /_/ /_/_/       /____/\\____/_____/_/  |_/_/ |_/_/  |_|   /____/_____/_/ |_|\n```\nSimple PHP SDK for interacting with the Transactions, Signatures, Borsh Serialization/Deserialization and RPCs\n---\nForked from the Verze repo:  [verze-app/solana-php-sdk](https://github.com/verze-app/solana-php-sdk/pull/53)\n\n---\n#### Motivations\n\n- To protect RPC API Keys acting as a Hosted Proxy. \n- To enable Background Data Processing.\n- To enable Descentralized Data \u0026 Query Caching. \n- To empower PHP Applications to interact with the Solana Network\n- To enable Async Jobs and Queries in the Background. \n- To enable Decetralized Websockets (Push Notifications \u0026 Subscriptions)\n- To reduce Client-Sice RPC Polling, aiming at decongesting the mainnet and devnets.   \n\n\n## Installation\n\nYou can install the package via composer :\n\n```bash\ncomposer require attestto/solana-php-sdk\n```\n### From this Repository\n\n```bash\ngit clone https://github.com/Attestto-com/solana-php-sdk.git\n\ncd solana-php-sdk\n\ncomposer install \n\n```\n### With Docker\n\n- [DockerFile](https://github.com/Attestto-com/solana-php-sdk/blob/master/Dockerfile) \n- [compose-dev.yaml](https://github.com/Attestto-com/solana-php-sdk/blob/master/compose-dev.yaml)\n\n```bash\ndocker build -t solana-php-sdk .\n```\nthen \n\n```bash\ndocker run -it solana-php-sdk /bin/bash\n```\n\n\n## Usage\n\n### Using the Solana simple client\n\nYou can use the `Connection` class for convenient access to API methods. Some are defined in the code:\n\n```php\nuse Attestto\\SolanaPhpSdk\\Connection;\nuse Attestto\\SolanaPhpSdk\\SolanaRpcClient;\n\n// Using a defined method\n$sdk = new Connection(new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT));\n$accountInfo = $sdk-\u003egetAccountInfo('4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA');\nvar_dump($accountInfo);\n```\n\nFor all the possible methods, see the [API documentation](https://docs.solana.com/developing/clients/jsonrpc-api).\n\n### Directly using the RPC client\n\nThe `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:\n\n```php\nuse Attestto\\SolanaPhpSdk\\SolanaRpcClient;\n\n$client = new SolanaRpcClient(SolanaRpcClient::MAINNET_ENDPOINT);\n$accountInfoResponse = $client-\u003ecall('getAccountInfo', ['4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA']);\n$accountInfoBody = $accountInfoResponse-\u003ejson();\n$accountInfoStatusCode = $accountInfoResponse-\u003egetStatusCode();\n``````\n\n### Transactions\n\nHere is working example of sending a transfer instruction to the Solana blockchain, you may overrride the Endpoint with a custom RPC endpoint.:\n\n```php\n$client = new SolanaRpcClient(SolanaRpcClient::DEVNET_ENDPOINT);\n$connection = new Connection($client);\n$fromPublicKey = KeyPair::fromSecretKey([...]);\n$toPublicKey = new PublicKey('J3dxNj7nDRRqRRXuEMynDG57DkZK4jYRuv3Garmb1i99');\n$instruction = SystemProgram::transfer(\n    $fromPublicKey-\u003egetPublicKey(),\n    $toPublicKey,\n    6\n);\n\n$transaction = new Transaction(null, null, $fromPublicKey-\u003egetPublicKey());\n$transaction-\u003eadd($instruction);\n\n$txHash = $connection-\u003esendTransaction($transaction, $fromPublicKey);\n```\n\n### Borsh Deserialize \u0026 Deserialize\n\nFor Borsh serialization/deseralization to work, a class::SCHEMA object reflecting the Program Structs, based on the program IDL must be passed or defined. e.g.\n\n```php\nclass DidData\n{\n\n    use BorshObject; //trait\n    public $keyData;\n\n    public const SCHEMA = [\n        VerificationMethodStruct::class =\u003e VerificationMethodStruct::SCHEMA[VerificationMethodStruct::class],\n        ServiceStruct::class =\u003e ServiceStruct::SCHEMA[ServiceStruct::class],\n        self::class =\u003e [\n            'kind' =\u003e 'struct',\n            'fields' =\u003e [\n                ['offset', 'u64'],\n                ['version', 'u8'],\n                ['bump', 'u8'],\n                ['nonce', 'u64'],\n                ['initialVerificationMethod', 'string'],\n                ['flags', 'u16'],\n                ['methodType', 'u8'],\n                ['keyData', ['u8']],\n                ['verificationMethods', [VerificationMethodStruct::class]],\n                ['services', [ServiceStruct::class]],\n                ['nativeControllers', ['pubKey']],\n                ['otherControllers', ['string']],\n            ],\n        ],\n    ];\n\n    public static function fromBuffer(array $buffer): self\n    {\n        return Borsh::deserialize(self::SCHEMA, self::class, $buffer);\n    }\n}\n```\n## BORSH USAGE (PHP implementation)\n\nTo get a better understanding on the implementation and usage, please refer to the following references: \n\n- [PHP Borsh Test](https://github.com/Attestto-com/solana-php-sdk/blob/master/tests/Unit/BorshTest.php)\n- [PHP Borsh Class](https://github.com/Attestto-com/solana-php-sdk/blob/master/src/Borsh/Borsh.php)\n- [PHP Borsh Trait](https://github.com/Attestto-com/solana-php-sdk/blob/master/src/Borsh/BorshObject.php)\n\nexample usage _**(This will be improved, WIP)**_: \n```php\n/**\n     * deserializeDidData\n     *\n     * @param string $dataBase64 The base64 encoded data of the DID data account\n     * @return DidData The deserialized DID data object\n     * @example DidSolProgram::deserializeDidData('TVjvjfsd7fMA/gAAAA...');\n     */\n    static function deserializeDidData($dataBase64)\n    {\n\n        $base64String = base64_decode($dataBase64);\n        $uint8Array = array_values(unpack('C*', $base64String));\n        $didData = DidData::fromBuffer($uint8Array); // See above code block\n\n        $keyData = $didData-\u003ekeyData;\n\n        $binaryString = pack('C*', ...$keyData);\n\n        $b58 = new Base58();\n        $base58String = $b58-\u003eencode($binaryString);\n        $didData-\u003ekeyData = $base58String;\n        return $didData;\n    }\n```\n\n## Notes:\n\n- Most of the Magic is done in the [BorshDesealizable.php](https://github.com/Attestto-com/solana-php-sdk/blob/master/src/Borsh/BorshDeserializable.php) Trait. \n- This project is in alpha, the code to generate instructions is still being worked on `$instruction = SystemProgram::abc()`\n- This project is maintained by a single dev, so any feedback, ideas, comments are appreciated. \n\n## Roadmap (WIP)\n\n1. Borsh serialize and deserialize. [Done](https://github.com/Attestto-com/solana-php-sdk/tree/master/src/Borsh) - [Test(s)](https://github.com/Attestto-com/solana-php-sdk/blob/master/tests/Unit/BorshTest.php) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src%2FBorsh)\n2. Improved documentation. [WIP](#) - This document + [Documentation Index](https://github.com/Attestto-com/solana-php-sdk/tree/master/docs) (https://github.com/Attestto-com/solana-php-sdk/tree/master/docs)\n3. Build out more of the Connection, Message, SystemProgram, TokenProgram, MetaplexProgram classes. [WIP](https://github.com/Attestto-com/solana-php-sdk/tree/master/src) - [Tests](https://github.com/Attestto-com/solana-php-sdk/tree/master/tests/Unit) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src)\n   4. [ ] Connection::class\n      5. [x] getLatestBlokchash::class [Source] - [Test] - [Coverage]\n      6. [ ] getMinimumBalanceForRentExemption()\n      7. [ ] getTokenAccountBalance()\n   6. [ ] TransactionMessage::class \n      7. [ ] compileToV0Message()\n   8. [ ] VersionedTransaction::class\n   9. [ ] SPL-TOKEN Program\n      10. [ ] getOrCreateAssociatedTokenAccount()\n      11. [ ] getAssociatedTokenAddressSync()\n      12. [ ] createAssociatedTokenAccountInstruction()\n      11. [ ] createSyncNativeInstruction() - [Test][Coverage]\n      \n4. Improve abstractions around working with binary data. [Done?](https://github.com/Attestto-com/solana-php-sdk/tree/master/src/Borsh) - [Test(s)](https://github.com/Attestto-com/solana-php-sdk/blob/master/tests/Unit/BorshTest.php) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src%2FBorsh)\n5. Optimizations:\n   1. Leverage PHP more.\n   2. Better cache `$recentBlockhash` when sending transactions. \n6. Suggestions? Open an [Issue](https://github.com/Attestto-com/solana-php-sdk/issues) or [Pull Request](https://github.com/Attestto-com/solana-php-sdk/pulls) :D\n\n## Testing \u0026 Code Coverage\n\nWIP -- Working on coverage and deprecations. See [Coverage Report](https://app.codecov.io/github/Attestto-com/solana-php-sdk).\n\n- Configuration [phpunit.xml](https://github.com/Attestto-com/solana-php-sdk/blob/master/phpUnit.xml)\n- composer.json\n```json\n   \"scripts\": {\n        \"test\": \"vendor/bin/phpunit tests --coverage-clover=coverage.xml --coverage-filter src/\",\n        \"format\": \"vendor/bin/php-cs-fixer fix --allow-risk=yes\"\n    },\n```\n[![GitHub Tests Action Status](https://github.com/Attestto-com/solana-php-sdk/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/Attestto-com/solana-php-sdk/actions/workflows/run-tests.yml)\n[![Coverage (CodeCov)](https://codecov.io/github/Attestto-com/solana-php-sdk/graph/badge.svg?token=M12LECZ9QE)](https://codecov.io/github/Attestto-com/solana-php-sdk)\n\n\n```bash\ncomposer test\n```\nOR\n\n```bash\n/verdor/bin/phpunit tests [options]\n```\n\n## Contributing - Yes Please! :-P\n\n- Please see [CONTRIBUTING](CONTRIBUTING.md) for details.\n- I will change my profile pic once we get a 2nd mantainer onboard :-)\n\n\n## Security\n\nIf you discover any security related issues, please email the maintainers (see composer.json) instead of using the issue tracker.\n\n## Credits\n\n- [Matt Stauffer](https://github.com/mattstauffer) (Original creator)\n- [Zach Vander Velden](https://github.com/exzachlyvv) (Metadata wizard)\n- [Neverything](https://github.com/verze-app/solana-php-sdk/graphs/contributors) (Previous Maintainer)\n- [All Contributors](../../contributors)\n  \n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattestto-com%2Fsolana-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattestto-com%2Fsolana-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattestto-com%2Fsolana-php-sdk/lists"}