Skip to content

blockfrost/blockfrost-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status

blockfrost-php


PHP SDK for Blockfrost.io API.

Getting startedInstallationUsage


Getting started

To use this SDK, you first need login into to blockfrost.io create your project to retrive your API token.


Installation

Composer

This SDK uses guzzlehttp for REST. Composer is the preferred package manager to import this:

composer.json

{
	"require" : {
		"guzzlehttp/guzzle" : "^7.0"
	},
	"autoload" : {
		"psr-4" : {
			"Blockfrost\\" 		  : "../blockfrost_api/"
		}
	},
	"minimum-stability" : "dev",
	"require-dev": {
		"phpunit/phpunit": "^9.5"
	}
}
$ php composer.phar update

Usage

Using the SDK is pretty straight-forward as you can see from the following example.

Cardano

<?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();
}


?>