Skip to content

Commit 8c0f295

Browse files
committed
v2.0.0
1 parent ff165e0 commit 8c0f295

File tree

10 files changed

+80
-61
lines changed

10 files changed

+80
-61
lines changed

CONTRIBUTING.md

Whitespace-only changes.
File renamed without changes.

README.md

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,104 @@
11
# Etherscan Service
2-
32
[![tests](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml)
4-
[![Latest Stable Version](https://poser.pugx.org/slvler/ether/v)](https://packagist.org/packages/slvler/ether)
5-
[![Latest Unstable Version](https://poser.pugx.org/slvler/ether/v/unstable)](https://packagist.org/packages/slvler/ether)
6-
[![License](https://img.shields.io/github/license/slvler/etherscan-service)](https://packagist.org/packages/slvler/ether)
3+
[![Latest Stable Version](https://img.shields.io/packagist/v/slvler/ether.svg)](https://packagist.org/packages/slvler/ether)
74
[![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether)
8-
5+
[![License](https://poser.pugx.org/slvler/ether/license)](https://packagist.org/packages/slvler/ether)
96

107
An api service for etherscan.io
118

12-
## Installation
9+
## Requirements
10+
- PHP 8.2
11+
- Laravel 9.x | 10.x | 11.x
1312

13+
## Installation
1414
To install this package tou can use composer:
15-
1615
```bash
1716
composer require slvler/ether
1817
```
1918

2019
## Usage
21-
2220
- First, you should extract the config/etherscan.php file to the config folder.
23-
2421
```php
2522
php artisan vendor:publish --tag=ether
2623
```
27-
2824
- First of all we'll add the API key and API Url of the service we're using to our .env file of our project. If you don't have an account yet on api.etherscan.io, you should create one. Once you have an account you can copy your API key from the dashboard page and put it into you .env file.
29-
3025
```php
3126
ETHERSCAN_BASE_URL=https://api.etherscan.io/
3227
ETHERSCAN_API_KEY=YOUR-API-KEY
3328
```
34-
3529
- This is how you can connect to the etherscan api service.
3630
- Returns the Ether balance of a given address.
37-
3831
```php
3932
$ether = new EtherScanService();
4033
$ether->balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
4134
```
42-
4335
- Returns the balance of the accounts from a list of addresses.
44-
4536
```php
4637
$data = [
4738
'0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
4839
'0x63a9975ba31b0b9626b34300f7f627147df1f526',
4940
'0x198ef1ec325a96cc354c7266a038be8b5c558f67'
5041
];
51-
5242
$ether = new EtherScanService();
5343
$ether->balance_multiple($data);
5444
```
55-
-
5645
- Returns the list of transactions performed by an address, with optional pagination.
57-
5846
```php
5947
$ether = new EtherScanService();
6048
$ether->transactions_normal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
6149
```
62-
6350
- Returns the list of internal transactions performed by an address, with optional pagination.
64-
6551
```php
6652
$ether = new EtherScanService();
6753
$ether->transactions_internal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
6854
```
69-
7055
- Returns the list of internal transactions performed within a transaction.
71-
7256
```php
7357
$ether = new EtherScanService();
7458
$ether->transactions_internal_hash('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
7559
```
76-
7760
- Returns the list of internal transactions performed within a block range, with optional pagination.
78-
7961
```php
8062
$ether = new EtherScanService();
8163
$ether->transactions_internal_block_range();
8264
```
83-
8465
- Returns the list of ERC-20 tokens transferred by an address, with optional filtering by token contract.
85-
8666
```php
8767
$ether = new EtherScanService();
8868
$ether->token_transfer_events_erc20();
8969
```
90-
9170
- Returns the list of ERC-721 ( NFT ) tokens transferred by an address, with optional filtering by token contract.
92-
9371
```php
9472
$ether = new EtherScanService();
9573
$ether->token_transfer_events_erc721();
9674
```
97-
9875
- Returns the list of ERC-1155 ( Multi Token Standard ) tokens transferred by an address, with optional filtering by token contract.
99-
10076
```php
10177
$ether = new EtherScanService();
10278
$ether->token_transfer_events_erc1155();
10379
```
104-
10580
- Returns the list of blocks mined by an address.
106-
10781
```php
10882
$ether = new EtherScanService();
10983
$ether->address_blocks_mined();
11084
```
111-
11285
- Returns the balance of an address at a certain block height. - PRO
113-
11486
```php
11587
$ether = new EtherScanService();
11688
$ether->balance_single_adress();
11789
```
11890

11991
### Testing
120-
12192
```bash
12293
composer test
12394
```
12495

12596
## Credits
126-
12797
- [slvler](https://github.com/slvler)
12898

129-
13099
## License
100+
The MIT License (MIT). Please see [License File](https://github.com/slvler/etherscan-service/blob/main/LICENSE.md) for more information.
131101

132-
The MIT License (MIT). Please see [License File](https://github.com/slvler/etherscan-service/blob/main/README.md) for more information.
102+
## Contributing
103+
You're very welcome to contribute.
104+
Please see [CONTRIBUTING](https://github.com/slvler/etherscan-service/blob/main/CONTRIBUTING.md) for details.

composer.json

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
11
{
22
"name": "slvler/ether",
3+
"description": "Laravel etherscan.io api service",
34
"license": "MIT",
4-
"description": "An api service for etherscan.io",
5-
"type": "package",
5+
"keywords": [
6+
"etherscan",
7+
"multichain",
8+
"laravel",
9+
"php"
10+
],
611
"authors": [
712
{
813
"name": "slvler",
914
"email": "[email protected]"
1015
}
1116
],
17+
"homepage": "https://github.com/slvler/etherscan-service",
18+
"require": {
19+
"php": "^8.2",
20+
"guzzlehttp/guzzle": "^7.2",
21+
"illuminate/support": "^9.0|^10.0|^11.0"
22+
},
23+
"require-dev": {
24+
"friendsofphp/php-cs-fixer": "^3.6",
25+
"orchestra/testbench": "^7.0",
26+
"phpunit/phpunit": "^9.5.8",
27+
"laravel/pint": "^1.18"
28+
},
1229
"autoload": {
1330
"psr-4": {
14-
"slvler\\ether\\": "src/"
31+
"Slvler\\Ether\\": "src/"
1532
}
1633
},
1734
"autoload-dev": {
1835
"psr-4": {
19-
"slvler\\ether\\Tests\\": "tests/"
36+
"Slvler\\Ether\\Tests\\": "tests/"
2037
}
2138
},
22-
"require": {},
23-
"require-dev": {
24-
"orchestra/testbench": "^6.18.0",
25-
"phpunit/phpunit": "^9.5",
26-
"guzzlehttp/guzzle": "^7.0.1"
27-
},
28-
"scripts": {
29-
"test": "vendor/bin/phpunit tests"
30-
},
3139
"extra": {
3240
"laravel": {
3341
"providers": [
34-
"slvler\\ether\\EtherServiceProvider"
42+
"Slvler\\Ether\\EtherServiceProvider"
3543
]
3644
}
3745
},
38-
"minimum-stability": "dev",
46+
"scripts": {
47+
"test": "vendor/bin/phpunit tests --colors=always",
48+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
49+
"pint": "vendor/bin/pint",
50+
"post-create-project-cmd": [
51+
"@php artisan key:generate --ansi"
52+
]
53+
},
54+
"minimum-stability": "stable",
3955
"prefer-stable": true
4056
}

config/etherscan.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
|
1212
*/
1313
'ether' => [
14-
'etherscan_url' => env('ETHERSCAN_BASE_URL'),
15-
'etherscan_key' => env('ETHERSCAN_API_KEY'),
14+
'base_url' => env('ETHERSCAN_BASE_URL'),
15+
'api_key' => env('ETHERSCAN_API_KEY'),
1616
],
17-
1817
];

src/Exception/ErrorException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Slvler\Ether\Exception;
4+
5+
class ErrorException {}

src/Exception/MissingApiKey.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Slvler\Ether\Exception;
4+
5+
use InvalidArgumentException;
6+
7+
class MissingApiKey extends InvalidArgumentException
8+
{
9+
public static function create(): self
10+
{
11+
return new self(
12+
'The Etherscan API Key is missing. Please publish the [etherscan.php] configuration file and set the [api_key].'
13+
);
14+
}
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Slvler\Ether\Exception;
4+
5+
class MissingArgumentException {}

src/Resources/Balance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace slvler\ether\Resources;
3+
namespace Slvler\Ether\Resources;
44

55
use Illuminate\Http\Resources\Json\JsonResource;
66

src/Services/EtherScanService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace slvler\ether\Services;
3+
namespace Slvler\Ether\Services;
44

5-
use slvler\ether\Resources\Balance;
5+
use Slvler\Ether\Exception\MissingApiKey;
6+
use Slvler\Ether\Resources\Balance;
67

78
class EtherScanService
89
{
@@ -12,8 +13,14 @@ class EtherScanService
1213

1314
public function __construct()
1415
{
15-
$this->base_url = config('etherscan.ether.etherscan_url');
16-
$this->api_key = config('etherscan.ether.etherscan_key');
16+
17+
$apiKey = config('etherscan.ether.api_key');
18+
if (empty($apiKey) || ! isset($apiKey)) {
19+
throw MissingApiKey::create();
20+
}
21+
22+
$this->base_url = config('etherscan.ether.base_url');
23+
$this->api_key = $apiKey;
1724

1825
$this->client = new \GuzzleHttp\Client(
1926
['base_uri' => $this->base_url]

0 commit comments

Comments
 (0)