PHP code example of fireblocks / fireblocks-php-sdk
1. Go to this page and download the library: Download fireblocks/fireblocks-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Fireblocks\Sdk\Api\FireblocksClient;
class WalletController extends Controller
{
public function index(FireblocksClient $fireblocks)
{
// List vault accounts
$accounts = $fireblocks->vaults()->listAccounts();
// Get specific account
$account = $fireblocks->vaults()->getAccount('0');
return response()->json($accounts);
}
}
use Fireblocks;
// List all vault accounts
$accounts = Fireblocks::vaults()->listAccounts();
// Create a new transaction
use Fireblocks\Sdk\Models\TransactionRequest;
$request = new TransactionRequest();
$request
->withAsset('BTC')
->withAmount('0.1')
->fromVaultAccount('0')
->toOneTimeAddress('bc1q...')
->withNote('Test transaction');
$transaction = Fireblocks::transactions()->create($request);
use Fireblocks\Sdk\Models\TransactionRequest;
// Transfer between vault accounts
$request = (new TransactionRequest())
->withAsset('BTC')
->withAmount('0.5')
->fromVaultAccount('source-vault-id')
->toVaultAccount('destination-vault-id')
->withNote('Internal transfer')
->withExternalTxId('external-ref-123');
// Transfer to external address
$request = (new TransactionRequest())
->withAsset('ETH')
->withAmount('1.0')
->fromVaultAccount('0')
->toOneTimeAddress('0x...', 'memo-tag') // optional tag
->withFeeLevel('HIGH');
// Transfer to exchange
$request = (new TransactionRequest())
->withAsset('USDC')
->withAmount('1000')
->fromVaultAccount('0')
->toExchange('exchange-account-id');
use Fireblocks\Sdk\Exceptions\FireblocksException;
use Fireblocks\Sdk\Exceptions\AuthenticationException;
use Fireblocks\Sdk\Exceptions\ValidationException;
use Fireblocks\Sdk\Exceptions\NotFoundException;
use Fireblocks\Sdk\Exceptions\RateLimitException;
try {
$transaction = $fireblocks->transactions()->create($request);
} catch (ValidationException $e) {
// Handle validation errors
$errors = $e->getErrors();
} catch (NotFoundException $e) {
// Resource not found
} catch (RateLimitException $e) {
// Rate limited - check $e->getRetryAfter()
sleep($e->getRetryAfter());
} catch (AuthenticationException $e) {
// Invalid API key or secret
} catch (FireblocksException $e) {
// Generic Fireblocks error
$errorCode = $e->getErrorCode();
$errorData = $e->getErrorData();
}
use Fireblocks\Sdk\Api\FireblocksClient;
class WebhookController extends Controller
{
public function handle(Request $request, FireblocksClient $fireblocks)
{
// Verify webhook signature
$publicKey = $fireblocks->webhooks()->getPublicKey()['publicKey'];
// Validate signature...
$event = $request->all();
match ($event['type']) {
'TRANSACTION_CREATED' => $this->handleTransactionCreated($event),
'TRANSACTION_COMPLETED' => $this->handleTransactionCompleted($event),
'TRANSACTION_FAILED' => $this->handleTransactionFailed($event),
default => null,
};
return response()->noContent();
}
}