1. Go to this page and download the library: Download mrokwor/blockchain-sdk-php 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/ */
mrokwor / blockchain-sdk-php example snippets
use BlockchainSdk\Laravel\Rules\BlockchainAddress;
use Illuminate\Http\Request;
public function swap(Request $request)
{
$network = $request->input('destination_network'); // e.g. 'solana', 'bsc', 'tron', 'bitcoin'
$request->validate([
'recipient_address' => ['
use BlockchainSdk\Laravel\Facades\Blockchain;
$driver = Blockchain::driver('polygon');
// Automatically fuels exact MATIC/POL gas from master gas station -> sweeps USDT
$result = $driver->sweepTokenWithGasSponsorship(
subWalletPrivateKey: $subWalletPrivateKey,
masterGasPrivateKey: Blockchain::getMasterGasKey('polygon'),
toVaultAddress: Blockchain::getMasterWallet('polygon'),
tokenContract: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F' // USDT
);
namespace App\Listeners;
use BlockchainSdk\Laravel\Events\WalletSwept;
class CreditUserOnSweepListener
{
/**
* Handle the event. Replace placeholder logic with your application's accounting flow.
*/
public function handle(WalletSwept $event): void
{
$sweep = $event->sweep;
$wallet = $sweep->wallet; // Associated BlockchainSdkWallet instance
if ($wallet && $wallet->user_id) {
$user = \App\Models\User::find($wallet->user_id);
// Example: Credit your application's user balance column
// Replace '{{your_balance_column}}' with your actual column (e.g. 'balance', 'wallet_balance', 'usd_balance')
$user->increment('{{your_balance_column}}', $sweep->amount);
// Or call your custom accounting / ledger service:
// LedgerService::creditUser($user->id, $sweep->amount, $sweep->token_symbol, $sweep->tx_hash);
// Mark the sweep as credited in the database ledger
$sweep->markAsCredited();
logger()->info("Credited {$sweep->amount} {$sweep->token_symbol} to User #{$user->id} on sweep Tx: {$sweep->tx_hash}");
}
}
}
namespace App\Listeners;
use BlockchainSdk\Laravel\Events\DepositConfirmed;
class CreditUserOnDepositListener
{
/**
* Handle the event. Replace placeholder logic with your application's accounting flow.
*/
public function handle(DepositConfirmed $event): void
{
$deposit = $event->deposit;
$wallet = $deposit->wallet;
if ($wallet && $wallet->user_id && !$deposit->is_credited) {
$user = \App\Models\User::find($wallet->user_id);
// Example: Credit your application's user balance column immediately
// Replace '{{your_balance_column}}' with your actual column name
$user->increment('{{your_balance_column}}', $deposit->amount);
$deposit->markAsCredited();
}
}
}