make-software / casper-php-sdk
PHP 7.4+ library for interacting with Casper blockchain node RPC API.
Installs: 1 825
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 7
Forks: 7
Open Issues: 2
Requires
- php: >=7.4
- ext-curl: *
- ext-gmp: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- ext-sodium: *
- ionux/phactor: 1.0.8
- paragonie/ecc: ^2.3
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-03-14 08:52:41 UTC
README
The PHP SDK allows developers to interact with the Casper Network using PHP. This page covers different examples of using the SDK.
Install
composer require make-software/casper-php-sdk
Usage
Creating RpcClient
Create RpcClient
by passing node url and headers (optional) to constructor
$nodeUrl = 'http://127.0.0.1:7777'; $headers = array('Authorization' => 'Bearer 6ae6c8b31f09df244019ffef60c274e4'); // Optional $client = new Casper\Rpc\RpcClient($nodeUrl, $headers);
RPC call examples
You can find all RpcClient methods on the RpcClientAPI page. Here you can see a several of examples of using RpcClient. All examples below are supposed to be ran against the Testnet
Get deploy by deploy hash
$deploy = $client->getDeploy('fa815fc43c38da30f6ab4e5a6c8a1b31f09df2bf4b344019ffef60c1270d4e49'); $deployHeader = $deploy->getHeader(); $creationTime = $deployHeader->getTimestamp();
Get auction state information
$auctionState = $client->getAuctionState(); $stateRootHash = $auctionState->getStateRootHash(); $blockHeight = $auctionState->getBlockHeight();
Get peers from the network
$peers = $client->getPeers(); foreach ($peers as $peer) { ... }
Get the latest block information
$latestBlock = $client->getLatestBlock(); $latestBlockHash = $latestBlock->getHash();
More examples
API
RpcClient
- RpcClient
- putDeploy
- getDeploy
- getBlockByHash
- getBlockByHeight
- getLatestBlock
- getPeers
- getStatus
- getAuctionState
- getStateRootHash
- getAccount
- getAccountBalance
- getAccountBalanceUrefByAccountHash
- getAccountBalanceUrefByPublicKey
- getBlockState
- getBlockTransfers
- getEraSummaryBySwitchBlockHash
- getEraSummaryBySwitchBlockHeight
- getDictionaryItemByURef
- getGlobalStateByBlock
- getGlobalStateByStateRootHash
- queryBalance
- getChainspecInfo
- speculativeExecution
DeployService
ContractService
Entities
Testing
Run the following command from the project directory.
Replace http://127.0.0.1:7777
by the any Testnet node url before running
export CASPER_PHP_SDK_TEST_NODE_URL="http://127.0.0.1:7777" && php vendor/bin/phpunit tests