A PHP library for interacting with BNB Smart Chain (BSC).
All blockchain interactions go through the ProxyApi interface.
It defines:
- sending raw transactions
- querying balances
eth_call- fetching nonces
- reading blocks and transaction receipts
- BscscanApi – uses BscScan HTTP endpoints
- NodeApi – uses JSON-RPC nodes
- Wallet generation: BIP39
- Key derivation: BIP44
Private keys are local only. Addresses derived with elliptic curves + keccak hashing.
Utils.php includes:
- hex encoding/decoding
- keccak hashing
- big number math
- wei ⇄ ether conversion
- decimal handling
- small HTTP helpers
Formatter.php converts method signatures (e.g. balanceOf(address))
into ABI-encoded call data (function selector + padded parameters)
for eth_call and contract calls.
Bnb.php builds raw transactions, signs them using the web3p/ethereum-tx library, and sends them via ProxyApi.
BEP20.php handles balances and transfers.
composer require web3p/ethereum-tx kornrunner/keccak phpseclib/phpseclib guzzlehttp/guzzlerequire __DIR__ . '/vendor/autoload.php';
use Binance\Wallet;
$account = Wallet::newAccountByMnemonic();
echo $account['mnemonic'] . PHP_EOL;
echo $account['address'] . PHP_EOL;
echo $account['key'] . PHP_EOL;use Binance\Wallet;
$account = Wallet::revertAccountByPrivateKey('0xYOUR_PRIVATE_KEY');
echo $account['address'] . PHP_EOL;require __DIR__ . '/vendor/autoload.php';
use Binance\BscscanApi;
use Binance\Formatter;
$bsc = new BscscanApi('YOUR_BSCSCAN_API_KEY', 'mainnet');
$address = '0xYourAddress';
$contract = '0x55d398326f99059fF775485246999027B3197955'; // USDT
$method = Formatter::toMethodFormat('balanceOf(address)');
$addr = Formatter::toAddressFormat($address);
$params = [
'to' => $contract,
'data' => '0x' . $method . $addr
];
$result = $bsc->ethCall($params);
var_dump($result);require __DIR__ . '/vendor/autoload.php';
use Binance\NodeApi;
use Binance\Bnb;
$node = new NodeApi(
'https://data-seed-prebsc-1-s1.binance.org:8545/',
null,
null,
'testnet'
);
$bnb = new Bnb($node);
$txHash = $bnb->transfer(
'0xYOUR_PRIVATE_KEY',
'0xRecipientAddress',
0.01
);
var_dump($txHash);This project is not affiliated with, endorsed by, or maintained by Binance or BNB Chain.