Giter VIP home page Giter VIP logo

ombews / bsc-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alvinnasa/bsc-php

0.0 0.0 0.0 31 KB

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.

Home Page: https://bsc-php.vercel.app

License: MIT License

PHP 100.00%

bsc-php's Introduction

English | δΈ­ζ–‡

BSC-PHP

Stable Version Php Version bsc-php License Total Downloads

Introduction

Support Binance's BNB and BEP20, which include functions such as address creation, balance query, transaction transfer, query the latest blockchain, query information based on the blockchain, and query information based on the transaction hash.

Advantage

  1. One set of scripts is compatible with all BNB currencies and BEP20 certifications in the BSC network
  2. Interface methods can be added or subtracted flexibly

Support Method

wallet

  • *Generate a private key to create an account newAccountByPrivateKey()
  • *Generate mnemonic and create an account newAccountByMnemonic()
  • Restore account using mnemonic revertAccountByMnemonic(string $mnemonic)
  • Get the address according to the private key revertAccountByPrivateKey(string $privateKey)

Bnb & BEP20

  • *Check balances(BNB) bnbBalance(string $address)
  • *Check balances(BEP20) balance(string $address)
  • Transaction transfer (offline signature) transfer(string $from, string $to, float $amount)
  • Query the latest block blockNumber()
  • Query information according to the blockchain getBlockByNumber(int $blockID)
  • *Query information based on transaction hash getTransactionReceipt(string $txHash)
  • *Query transaction status based on transaction hash receiptStatus(string $txHash)

Quick Start

Install

PHP8

composer require fenguoz/bsc-php

or PHP7

composer require fenguoz/bsc-php ~1.0

Interface

Wallet

$wallet = new \Binance\Wallet();

// Generate a private key to create an account
$wallet->newAccountByPrivateKey();

// Generate mnemonic and create an account
$wallet->newAccountByMnemonic();

// Restore account using mnemonic
$mnemonic = 'elite link code extra twist autumn flower purse excuse harsh kitchen whip';
$wallet->revertAccountByMnemonic($mnemonic);

// Get the address according to the private key
$privateKey = '5e9340935f4c02628cec5d04cc281012537cafa8dae0e27ff56563b8dffab368';
$wallet->revertAccountByPrivateKey($privateKey);

Bnb & BEP20

## Method 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);

## Method 2 : Bscscan Api
$apiKey = 'QVG2GK41ASNSD21KJTXUAQ4JTRQ4XUQZCX';
$api = new \Binance\BscscanApi($apiKey);

$bnb = new \Binance\Bnb($api);

$config = [
    'contract_address' => '0x55d398326f99059fF775485246999027B3197955',// USDT BEP20
    'decimals' => 18,
];
$bep20 = new \Binance\BEP20($api, $config);

// *Check balances
$address = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
$bnb->bnbBalance($address);
$bep20->balance($address);

// Transaction transfer (offline signature)
$from = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
$to = '0x1667ca2c72d8699f0c34c55ea00b60eef021****';
$amount = 0.1;
$bnb->transfer($from, $to, $amount);
$bep20->transfer($from, $to, $amount);

// Query the latest block
$bnb->blockNumber();
$bep20->blockNumber();

// Query information according to the blockchain
$blockID = 24631027;
$bnb->getBlockByNumber($blockID);
$bep20->getBlockByNumber($blockID);

// Query information based on transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$bnb->getTransactionReceipt($txHash);
$bep20->getTransactionReceipt($txHash);

// Query transaction status based on transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$bnb->receiptStatus($txHash);
$bep20->receiptStatus($txHash);

Plan

  • Support ERC721|ERC-1155
  • Smart Contract

🌟🌟

Stargazers over time

Cooperate

Contact

  • WX:zgf243944672
  • QQ:243944672

bsc-php's People

Contributors

fenguoz avatar alvinnasa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.