|
| 1 | +# PHP wrapper for the Etherscan API (supports v2). |
| 2 | + |
| 3 | +PHP client for [Etherscan API](https://docs.etherscan.io) (and its families like BscScan), with nearly full API bindings |
| 4 | +(accounts, transactions, tokens, contracts, blocks, stats) and full [chains](https://docs.etherscan.io/supported-chains) support. |
| 5 | + |
| 6 | + |
| 7 | +**Table of Contents** |
| 8 | +- [Installation](#installation) |
| 9 | +- [Quick Start](#quick-start) |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +composer req seregazhuk/etherscan-api |
| 15 | +``` |
| 16 | + |
| 17 | +## Quick Start |
| 18 | + |
| 19 | +Register Etherscan account and create [free API key](https://etherscan.io/myapikey). |
| 20 | + |
| 21 | +```php |
| 22 | +$etherscan = new seregazhuk\EtherscanApi\EtherscanApi('your-api-key'); |
| 23 | +$currentBlock = $etherscan->proxy->getBlockNumber(); |
| 24 | +$transactionInfo = $etherscan->proxy->getTransactionByHash('0x136f818dfe87b367eee9890c162ef343dbd65e409aef102219a6091ba7e696d7'); |
| 25 | +$isConfirmed = $currentBlock |
| 26 | + ->subtract($transactionInfo->blockNumber) |
| 27 | + ->compare(new BigInteger('12')) >= 0; |
| 28 | + |
| 29 | +echo $isConfirmed ? 'Confirmed' : 'Not confirmed'; |
| 30 | +``` |
| 31 | + |
| 32 | +## Available bindings |
| 33 | + |
| 34 | +### Accounts |
| 35 | + |
| 36 | +https://docs.etherscan.io/api-endpoints/accounts#get-ether-balance-for-a-single-address |
| 37 | +Get Ether balance for a single address: |
| 38 | + |
| 39 | +```php |
| 40 | +$balance = $this->accounts->getBalance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); |
| 41 | +``` |
| 42 | + |
| 43 | +https://docs.etherscan.io/api-endpoints/accounts#get-ether-balance-for-multiple-addresses-in-a-single-call |
| 44 | +Get Ether balance for multiple addresses in a single call: |
| 45 | + |
| 46 | +```php |
| 47 | +$balances = $this->accounts->getBalances(['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', '0x63a9975ba31b0b9626b34300f7f627147df1f526']); |
| 48 | +``` |
| 49 | + |
| 50 | +https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address |
| 51 | +Get a list of 'Normal' transactions by address: |
| 52 | +```php |
| 53 | +$transactions = $this->accounts->getTransactions('0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC'); |
| 54 | +``` |
0 commit comments