Skip to content

Commit

Permalink
Optimize the description of README and example files
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenguoz committed Jul 25, 2024
1 parent ed989a0 commit fb240fa
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
16 changes: 8 additions & 8 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ $mnemonic = 'elite link code extra twist autumn flower purse excuse harsh kitche
$wallet->revertAccountByMnemonic($mnemonic);

// 根据私钥得到地址
$privateKey = '5e9340935f4c02628cec5d04cc281012537cafa8dae0e27ff56563b8dffab368';
$privateKey = '5e9340935f4c02****f56563b8dffab368';
$wallet->revertAccountByPrivateKey($privateKey);
```

Expand All @@ -79,7 +79,7 @@ $uri = 'https://bsc-dataseed1.defibit.io/';// Mainnet
$api = new \Binance\NodeApi($uri);

## 方法 2 : Bscscan Api
$apiKey = 'QVG2GK41ASNSD21KJTXUAQ4JTRQ4XUQZCX';
$apiKey = 'QVG2GK41A****RQ4XUQZCX';
$api = new \Binance\BscscanApi($apiKey);

$bnb = new \Binance\Bnb($api);
Expand All @@ -91,13 +91,13 @@ $config = [
$bep20 = new \Binance\BEP20($api, $config);

// 查询余额
$address = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
$address = '0x1667ca2c7****021be3a';
$bnb->bnbBalance($address);
$bep20->balance($address);

// 交易转账(离线签名)
$from = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
$to = '0x1667ca2c72d8699f0c34c55ea00b60eef021****';
$from = '0x1667ca2c7****021be3a';
$to = '0xd8699f0****b60eef021';
$amount = 0.1;
$bnb->transfer($from, $to, $amount);
$bep20->transfer($from, $to, $amount);
Expand All @@ -112,17 +112,17 @@ $bnb->getBlockByNumber($blockID);
$bep20->getBlockByNumber($blockID);

// 根据交易哈希返回交易的收据
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionReceipt($txHash);
$bep20->getTransactionReceipt($txHash);

// 根据交易哈希返回关于所请求交易的信息
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionByHash($txHash);
$bep20->getTransactionByHash($txHash);

// 根据交易哈希查询交易状态
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->receiptStatus($txHash);
$bep20->receiptStatus($txHash);
```
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ composer require fenguoz/bsc-php ~1.0
### Interface

#### Wallet
[example.php](./example.php#L4)
``` php
$wallet = new \Binance\Wallet();

Expand All @@ -64,23 +65,24 @@ $wallet->newAccountByPrivateKey();
$wallet->newAccountByMnemonic();

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

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

#### Bnb & BEP20
[example.php](./example.php#L23)
``` php
## 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';
$apiKey = 'QVG2GK41A****RQ4XUQZCX';
$api = new \Binance\BscscanApi($apiKey);

$bnb = new \Binance\Bnb($api);
Expand All @@ -92,13 +94,13 @@ $config = [
$bep20 = new \Binance\BEP20($api, $config);

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

// Transaction transfer (offline signature)
$from = '0x1667ca2c72d8699f0c34c55ea00b60eef021be3a';
$to = '0x1667ca2c72d8699f0c34c55ea00b60eef021****';
$from = '0x1667ca2c7****021be3a';
$to = '0xd8699f0****b60eef021';
$amount = 0.1;
$bnb->transfer($from, $to, $amount);
$bep20->transfer($from, $to, $amount);
Expand All @@ -113,17 +115,17 @@ $bnb->getBlockByNumber($blockID);
$bep20->getBlockByNumber($blockID);

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

// Returns the information about a transaction requested by transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionByHash($txHash);
$bep20->getTransactionByHash($txHash);

// Query transaction status based on transaction hash
$txHash = '0x4dd20d01af4c621d2fc293dff17a8fd8403ea3577988bfb245a18bfb6f50604b';
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->receiptStatus($txHash);
$bep20->receiptStatus($txHash);
```
Expand Down
73 changes: 61 additions & 12 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,76 @@
<?php
include './vendor/autoload.php';

// Wallet
/**
* Wallet
*/
$wallet = new \Binance\Wallet();
$addressData = $wallet->newAccountByPrivateKey();

// Bnb & BEP20
# Method 1 : BSC RPC Nodes
// 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....';
$wallet->revertAccountByMnemonic($mnemonic);

// Get the address according to the private key
$privateKey = '5e9340935f4c02****f56563b8dffab368';
$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';
## Method 2 : Bscscan Api
$apiKey = 'QVG2GK41A****RQ4XUQZCX';
$api = new \Binance\BscscanApi($apiKey);

$address = '0x685B1ded8013785d6623CC18D214320b6Bb64759';
$bnbWallet = new \Binance\Bnb($api);
$bnbBalance = $bnbWallet->bnbBalance($address);
$bnb = new \Binance\Bnb($api);

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

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

// Transaction transfer (offline signature)
$from = '0x1667ca2c7****021be3a';
$to = '0xd8699f0****b60eef021';
$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 = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionReceipt($txHash);
$bep20->getTransactionReceipt($txHash);

// Returns the information about a transaction requested by transaction hash
$txHash = '0x4dd20d01af4c621d2f****77988bfb245a18bfb6f50604b';
$bnb->getTransactionByHash($txHash);
$bep20->getTransactionByHash($txHash);

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

0 comments on commit fb240fa

Please sign in to comment.