Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fenguoz/bsc-php
Support Binance Smart Chain BNB/BEP20 digital assets, including address creation, balance query, transaction transfer, query the latest blockchain, query information based on blockchain, query information based on transaction hash, etc.
https://github.com/fenguoz/bsc-php
bep20 binance binance-chain bnb bsc php
Last synced: 3 days ago
JSON representation
Support Binance Smart Chain BNB/BEP20 digital assets, including address creation, balance query, transaction transfer, query the latest blockchain, query information based on blockchain, query information based on transaction hash, etc.
- Host: GitHub
- URL: https://github.com/fenguoz/bsc-php
- Owner: Fenguoz
- License: mit
- Created: 2022-05-07T06:08:07.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T08:17:47.000Z (4 months ago)
- Last Synced: 2024-12-01T04:07:18.395Z (21 days ago)
- Topics: bep20, binance, binance-chain, bnb, bsc, php
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 37
- Watchers: 3
- Forks: 40
- Open Issues: 12
-
Metadata Files:
- Readme: README-CN.md
- License: LICENSE
Awesome Lists containing this project
README
[English](./README.md) | 中文
BSC-PHP
## 概述
BSC-PHP 目前支持币安智能链的 BNB 和 BEP20 数字资产常用的生成地址,发起转账,查询余额,离线签名等功能。
## 特点
1. 一套写法兼容 BSC 网络中 BNB 货币和 BEP20 系列所有通证
1. 接口方法可可灵活增减## 支持方法
### wallet
- *生成私钥创建账户 `newAccountByPrivateKey()`
- *生成助记词创建账户 `newAccountByMnemonic()`
- 使用助记词还原账户 `revertAccountByMnemonic(string $mnemonic)`
- 根据私钥得到地址 `revertAccountByPrivateKey(string $privateKey)`### Bnb & BEP20
- *查询余额(BNB) `bnbBalance(string $address)`
- *查询余额(BEP20) `balance(string $address)`
- *交易转账(离线签名) `transfer(string $from, string $to, float $amount)`
- 查询最新区块 `blockNumber()`
- 根据区块链查询信息 `getBlockByNumber(int $blockID)`
- 根据交易哈希返回交易的收据 `getTransactionReceipt(string $txHash)`
- *根据交易哈希返回关于所请求交易的信息 `getTransactionByHash(string $txHash)`
- *根据交易哈希查询交易状态 `receiptStatus(string $txHash)`## 快速开始
### 安装
PHP8
``` php
composer require fenguoz/bsc-php
```or PHP7
``` php
composer require fenguoz/bsc-php ~1.0
```### 接口调用
#### Wallet
``` php
$wallet = new \Binance\Wallet();// 生成私钥创建账户
$wallet->newAccountByPrivateKey();// 生成助记词创建账户
$wallet->newAccountByMnemonic();// 使用助记词还原账户
$mnemonic = 'elite link code extra twist autumn flower purse excuse harsh kitchen whip';
$wallet->revertAccountByMnemonic($mnemonic);// 根据私钥得到地址
$privateKey = '5e9340935f4c02****f56563b8dffab368';
$wallet->revertAccountByPrivateKey($privateKey);
```#### Bnb & BEP20
``` php
## 方法 1 : BSC RPC Nodes
$uri = 'https://bsc-dataseed1.defibit.io/';// Mainnet
// $uri = 'https://data-seed-prebsc-1-s1.binance.org:8545/';// Testnet
$api = new \Binance\NodeApi($uri);## 方法 2 : Bscscan Api
$apiKey = 'QVG2GK41A****RQ4XUQZCX';
$api = new \Binance\BscscanApi($apiKey);$bnb = new \Binance\Bnb($api);
$config = [
'contract_address' => '0x55d398326f99059fF775485246999027B3197955',// USDT BEP20
'decimals' => 18,
];
$bep20 = new \Binance\BEP20($api, $config);// 查询余额
$address = '0x1667ca2c7****021be3a';
$bnb->bnbBalance($address);
$bep20->balance($address);// 交易转账(离线签名)
$from = '0x1667ca2c7****021be3a';
$to = '0xd8699f0****b60eef021';
$amount = 0.1;
$bnb->transfer($from, $to, $amount);
$bep20->transfer($from, $to, $amount);// 查询最新区块
$bnb->blockNumber();
$bep20->blockNumber();// 根据区块链查询信息
$blockID = 24631027;
$bnb->getBlockByNumber($blockID);
$bep20->getBlockByNumber($blockID);// 根据交易哈希返回交易的收据
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionReceipt($txHash);
$bep20->getTransactionReceipt($txHash);// 根据交易哈希返回关于所请求交易的信息
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionByHash($txHash);
$bep20->getTransactionByHash($txHash);// 根据交易哈希查询交易状态
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->receiptStatus($txHash);
$bep20->receiptStatus($txHash);
```## 计划
- 支持 ERC721|ERC-1155
- 智能合约## 🌟🌟
[![Stargazers over time](https://starchart.cc/Fenguoz/bsc-php.svg)](https://starchart.cc/Fenguoz/bsc-php)
## 合作
联系方式
- WX:zgf243944672
- QQ:243944672