PHP SDK for Blockfrost.io API.
Getting started • Installation • Usage
To use this SDK, you first need login into to blockfrost.io create your project to retrive your API token.
This SDK uses guzzlehttp for REST. Composer is the preferred package manager to import this:
{
"require" : {
"guzzlehttp/guzzle" : "^7.0"
},
"autoload" : {
"psr-4" : {
"Blockfrost\\" : "../blockfrost_api/"
}
},
"minimum-stability" : "dev",
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
$ php composer.phar update
Using the SDK is pretty straight-forward as you can see from the following example.
<?php
use Blockfrost\Block\BlockService;
use Blockfrost\Service;
require __DIR__.'/vendor/autoload.php';
$projectId = "MY_PROJECT_ID";
$blockService = new BlockService(Service::$NETWORK_CARDANO_MAINNET, $projectId);
try
{
$res = $blockService->getLatestBlock();
echo $res->hash;
}
catch(Exception $err)
{
echo $err->getMessage();
}
?>