The Blockgum PHP library is designed to simplify interactions with the Blockgum API, allowing developers to integrate various blockchain-related functionalities into their PHP applications. This library provides methods to create addresses, retrieve transaction information, send transactions, and more.
To use the Blockgum PHP library, follow these steps:
-
Include the Library: Include the
Blockgum.php
file in your PHP project:require_once 'Blockgum.php';
-
Initialize the Blockgum Object: Create an instance of the
Blockgum
class with the necessary configuration options:$bg_config = [ 'api_url' => 'https://api.blockgum.io', // Blockgum API URL 'chain' => 'eth', // Blockchain chain (e.g., 'eth', 'bsc', 'matic') 'jwt_token' => 'YOUR_JWT_TOKEN', // JWT Token for authentication 'client_id' => 'YOUR_CLIENT_ID', // Client ID for authentication 'security_type' => 1, // Security type (0 for off, 1 for on) ]; $blockgum = new Common\Ext\Blockgum($bg_config);
Creates a new blockchain address for a user identified by their unique ID.
$uid = '23236';
$response = $blockgum->createAddress($uid);
Retrieves blockchain data associated with a user identified by their unique ID.
$uid = '23236';
$response = $blockgum->searchByUid($uid);
Creates a batch of blockchain addresses starting from a specific index.
$start = 0; // Starting index
$limit = 100; // Number of addresses to create
$response = $blockgum->create10k($start, $limit);
Searches for blockchain addresses based on a provided address.
$address = '0x123abc...';
$response = $blockgum->searchAddresses($address);
Performs a wildcard search for blockchain data based on the specified type and search term.
$type = 'type'; // Search type
$term = 'searchterm'; // Search term
$response = $blockgum->wildcardSearch($type, $term);
Retrieves withdrawal information for a specific order ID.
$order_id = 'order123';
$response = $blockgum->getWithdrawalInfo($order_id);
Retrieves details of a blockchain transaction by its transaction hash.
$tx_hash = '0xabcdef...';
$response = $blockgum->transaction($tx_hash);
Retrieves transaction information from the database based on a specific condition and transaction hash.
$where = 'condition'; // Database condition
$tx_hash = '0xabcdef...';
$response = $blockgum->transactionInfoDb($where, $tx_hash);
Traces a deposit transaction using its transaction hash.
$tx_hash = '0xabcdef...';
$response = $blockgum->traceDeposit($tx_hash);
Retrieves a list of blockchain addresses with optional pagination.
$page = 1; // Page number (optional)
$response = $blockgum->getAddressList($page);
Watches a token based on the contract information.
$contract = 'token_contract';
$response = $blockgum->watchToken($contract);
Deletes a token based on the contract information.
$contract = 'token_contract';
$response = $blockgum->deleteToken($contract);
Retrieves statistics related to the Blockgum service.
$response = $blockgum->stats();
Retrieves a list of available tokens.
$response = $blockgum->getTokenList();
Moves deposits to the main account.
$response = $blockgum->moveDepositsToMainAccount();
Restarts the Blockgum server.
$response = $blockgum->restartServer();
Retrieves information about the Blockgum service.
$response = $blockgum->about();
Checks if advanced security is enabled.
$response = $blockgum->isAdvancedSecurity();
Shuts down the Blockgum server.
$response = $blockgum->shutdownServer();
Signs into the Blockgum API.
$response = $blockgum->signInAPI();
Decodes an amount by dividing it by the specified number of decimals.
$val = '1000000000000000000'; // Amount in wei
$decimals = 18; // Number of decimals (optional, uses default if not provided)
$decodedAmount = $blockgum->amount_decode($val, $decimals);
Encodes an amount by multiplying it by the specified number of decimals.
$amount = '1.23456789'; // Amount
$decimals = 18; // Number of decimals (optional, uses default if not provided)
$encodedAmount = $blockgum->amount_encode($amount, $decimals);
The Blockgum PHP library also includes various private methods used internally for handling requests, generating JWT tokens, and more. These methods are not intended for direct use in your application.
The Blockgum PHP library includes basic error handling to help you manage and troubleshoot issues that may arise during API interactions. When an error occurs, the library returns an associative array with the following structure:
status
(integer): Indicates the status of the operation. A value of0
typically indicates an error.error
(string): Provides a human-readable error message describing the issue.errorCode
(string, optional): Specifies an error code to further categorize the error.
Here's an example of how to handle errors using the returned array:
$response = $blockgum->someMethod();
if ($response['status'] === 0) {
// An error occurred
$errorCode = $response['errorCode'] ?? null;
$errorMessage = $response['error'];
// Handle the error based on the errorCode or errorMessage
// You can log the error, display a user-friendly message, or take appropriate action.
} else {
// The operation was successful, process the response data as needed.
}