Giter Site home page Giter Site logo

fenguoz / bsc-php Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 32.0 21 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.

License: MIT License

PHP 100.00%
bsc php binance-chain bep20 bnb binance

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)
  • Returns the receipt of a transaction by transaction hash getTransactionReceipt(string $txHash)
  • *Returns the information about a transaction requested by transaction hash getTransactionByHash(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);

// Returns the receipt of a transaction by transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$bnb->getTransactionReceipt($txHash);
$bep20->getTransactionReceipt($txHash);

// Returns the information about a transaction requested by transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$bnb->getTransactionByHash($txHash);
$bep20->getTransactionByHash($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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bsc-php's Issues

sop/asn1 update needed

Hi
When I want to install it I get this error.
Please update sop/asn1.

Problem 1
- Root composer.json requires fenguoz/bsc-php ^0.1.0 -> satisfiable by fenguoz/bsc-php[0.1.0].
- fenguoz/bsc-php 0.1.0 requires sop/asn1 ^3.3 -> found sop/asn1[3.3.0, ..., 3.4.3] but it conflicts with your root composer.json require (^4.1).

Transfer not working

The transfer is not working...

 $uri = 'https://data-seed-prebsc-1-s1.binance.org:8545/';// Testnet
    $api = new \Binance\NodeApi($uri);
    $bnb = new \Binance\Bnb($api);
    $config = [
        'contract_address' => '0xA874AE9a50a1a9A4A21285AB188E324bb4b3fA2A',// USDT BEP20
        'decimals' => 8,
    ];
    $bep20 = new \Binance\BEP20($api, $config);
    
    $from = 'PRIVATE_KEY';
    $to = '0xebccc7556e93d16a95c6abcee1cd0586949b3c1f';
    $amount = 0.1;
    $f = $bep20->transfer($from, $to, $amount);
    var_dump($f);

returning false;

转账bnb出错

string(103) "{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"insufficient funds for gas * price + value"}}"

Error During BEP20 Transfer

Deprecated: Return type of Elliptic\Curve\ShortCurve\Point::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/reeocoin/public_html/testapp/vendor/simplito/elliptic-php/lib/Curve/ShortCurve/Point.php on line 84

Deprecated: Return type of Web3p\EthereumTx\Transaction::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/reeocoin/public_html/testapp/vendor/web3p/ethereum-tx/src/Transaction.php on line 292

Deprecated: Return type of Web3p\EthereumTx\Transaction::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/reeocoin/public_html/testapp/vendor/web3p/ethereum-tx/src/Transaction.php on line 323

Deprecated: Return type of Web3p\EthereumTx\Transaction::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/reeocoin/public_html/testapp/vendor/web3p/ethereum-tx/src/Transaction.php on line 252

Deprecated: Return type of Web3p\EthereumTx\Transaction::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/reeocoin/public_html/testapp/vendor/web3p/ethereum-tx/src/Transaction.php on line 308

new Address by private key

Can we create a new address based on public key or private key? so each new member balance is sum in main address ?

NULL Response BSC

I face error with no response while transfer BSC to other address

My request

$uri = 'https://data-seed-prebsc-1-s1.binance.org:8545/';// Testnet
$api = new \Binance\NodeApi($uri);
$address = '0x5454c66eaa964d13b7d858d79e85c877ccbf33ab';
$bnb = new \Binance\Bnb($api);
$bnbBalance = $bnb->bnbBalance($address);

$from = '3e2f3d8c699332a08c1c1158b7ff34548aca162580f91070cba930dfc9a7406b'; // private
$to = '0x43671E7c181e4908DEeBd84bd2d71ceAD4e2E84c';
$amount = 0.01;
$bnbtransfer = $bnb->transfer($from, $to, $amount);

Just log the function like this

$raw = $transaction->sign($privateKey);
logDebug("raw");
logDebug($raw);
$res = $this->proxyApi->sendRawTransaction('0x' . $raw);
logDebug($res);
return $res;

the response is NULL or EMPTY

response: raw
-------------------------
response: f86c8085012a05f2008276c09443671E7c181e4908DEeBd84bd2d71ceAD4e2E84c872386f26fc10000808193a002c05cfc47a5e64801b88f202131f216559ec189c2ce3eb9afcd42d61956c016a02eaa65e8f346efedb917b5b3ef32d71551cd9353883071447a31fcd2e03cbddc
-------------------------
response: 

any fix?

Donations

Put an address to make donations, you have to value the work, I needed this a lot and I'm interested in you continuing to develop it.

i face following problem when transfer BEP20

i face following problem when transfer
PHP Fatal error: Uncaught InvalidArgumentException: Invalid private key format. in /home/bk5cstaking/public_html/bep20_new/vendor/fenguoz/bsc-php/src/PEMHelper.php:97
Stack trace:
#0 /home/bk5cstaking/public_html/bep20_new/vendor/fenguoz/bsc-php/src/PEMHelper.php(83): Binance\PEMHelper::privateKeyToPublicKey('0x5475F17bC4EE2...')
#1 /home/bk5cstaking/public_html/bep20_new/vendor/fenguoz/bsc-php/src/BEP20.php(37): Binance\PEMHelper::privateKeyToAddress('0x5475F17bC4EE2...')
#2 /home/bk5cstaking/public_html/bep20_new/example.php(37): Binance\BEP20->transfer('0x5475F17bC4EE2...', '0x38E9b9302443d...', 1)
#3 {main}
thrown in /home/bk5cstaking/public_html/bep20_new/vendor/fenguoz/bsc-php/src/PEMHelper.php on line 97

What to do i dont understand...

its safe?

its safe to use generation wallet address feature? it will be conflict same address? what based algorithm? if someone run wallet generation 100 wallet/second and save to db. and have millon of address then they scan saved address everyday, the new address generation by other user it will be safe? thx u

composer 冲突

与fenguoz/tron-php冲突,由于guzzlehttp/guzzle版本导致的,能否升级bsc-php中的guzzle版本

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.