From 6b4f2c5259328e45e1dfdcfc37eed24a53b359bb Mon Sep 17 00:00:00 2001 From: slvler <56368718+slvler@users.noreply.github.com> Date: Mon, 13 Nov 2023 12:49:41 +0300 Subject: [PATCH 1/7] Update EtherScanService.php --- src/Services/EtherScanService.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Services/EtherScanService.php b/src/Services/EtherScanService.php index 51ffa8b..4b37ebe 100644 --- a/src/Services/EtherScanService.php +++ b/src/Services/EtherScanService.php @@ -12,10 +12,8 @@ class EtherScanService public function __construct() { - //$this->base_url = config('etherscan.ether.etherscan_url'); - //$this->api_key = config('etherscan.ether.etherscan_key'); - $this->base_url = 'https://api.etherscan.io/'; - $this->api_key = 'WI48Q1V6RFNY7E1U773E2J5EAB8A1ZG8UM'; + $this->base_url = config('etherscan.ether.etherscan_url'); + $this->api_key = config('etherscan.ether.etherscan_key'); $this->client = new \GuzzleHttp\Client( ['base_uri' => $this->base_url] From fbfa999c358d8c198fc9aef99a5bf0cd9d37063b Mon Sep 17 00:00:00 2001 From: slvler Date: Sat, 19 Oct 2024 23:23:36 +0300 Subject: [PATCH 2/7] update --- README.md | 84 ++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index c63ccf5..2b7441a 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,18 @@ -# slvler - Etherscan Service +# Etherscan Service [![tests](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml) -[![Latest Stable Version](http://poser.pugx.org/slvler/ether/v)](https://packagist.org/packages/slvler/ether) -[![Latest Unstable Version](http://poser.pugx.org/slvler/ether/v/unstable)](https://packagist.org/packages/slvler/ether) +[![Latest Stable Version](https://poser.pugx.org/slvler/ether/v)](https://packagist.org/packages/slvler/ether) +[![Latest Unstable Version](https://poser.pugx.org/slvler/ether/v/unstable)](https://packagist.org/packages/slvler/ether) [![License](https://img.shields.io/github/license/slvler/etherscan-service)](https://packagist.org/packages/slvler/ether) - - An api service for etherscan.io - ## Installation To install this package tou can use composer: ```bash - composer require slvler/ether +composer require slvler/ether ``` ## Usage @@ -23,116 +20,109 @@ To install this package tou can use composer: - First, you should extract the config/etherscan.php file to the config folder. ```php - php artisan vendor:publish --tag=ether +php artisan vendor:publish --tag=ether ``` - 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. - ```php - ETHERSCAN_BASE_URL=https://api.etherscan.io/ - ETHERSCAN_API_KEY=YOUR-API-KEY +ETHERSCAN_BASE_URL=https://api.etherscan.io/ +ETHERSCAN_API_KEY=YOUR-API-KEY ``` - This is how you can connect to the etherscan api service. - Returns the Ether balance of a given address. ```php - $ether = new EtherScanService(); - $ether->balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); +$ether = new EtherScanService(); +$ether->balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - Returns the balance of the accounts from a list of addresses. ```php - $data = [ - '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', - '0x63a9975ba31b0b9626b34300f7f627147df1f526', - '0x198ef1ec325a96cc354c7266a038be8b5c558f67' - ]; +$data = [ + '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', + '0x63a9975ba31b0b9626b34300f7f627147df1f526', + '0x198ef1ec325a96cc354c7266a038be8b5c558f67' +]; - $ether = new EtherScanService(); - $ether->balance_multiple($data); +$ether = new EtherScanService(); +$ether->balance_multiple($data); ``` - - +- - Returns the list of transactions performed by an address, with optional pagination. ```php - $ether = new EtherScanService(); - $ether->transactions_normal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); +$ether = new EtherScanService(); +$ether->transactions_normal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - - Returns the list of internal transactions performed by an address, with optional pagination. ```php - $ether = new EtherScanService(); - $ether->transactions_internal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); +$ether = new EtherScanService(); +$ether->transactions_internal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - Returns the list of internal transactions performed within a transaction. ```php - $ether = new EtherScanService(); - $ether->transactions_internal_hash('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'); +$ether = new EtherScanService(); +$ether->transactions_internal_hash('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'); ``` - Returns the list of internal transactions performed within a block range, with optional pagination. ```php - $ether = new EtherScanService(); - $ether->transactions_internal_block_range(); +$ether = new EtherScanService(); +$ether->transactions_internal_block_range(); ``` - - Returns the list of ERC-20 tokens transferred by an address, with optional filtering by token contract. ```php - $ether = new EtherScanService(); - $ether->token_transfer_events_erc20(); +$ether = new EtherScanService(); +$ether->token_transfer_events_erc20(); ``` - - Returns the list of ERC-721 ( NFT ) tokens transferred by an address, with optional filtering by token contract. ```php - $ether = new EtherScanService(); - $ether->token_transfer_events_erc721(); +$ether = new EtherScanService(); +$ether->token_transfer_events_erc721(); ``` - Returns the list of ERC-1155 ( Multi Token Standard ) tokens transferred by an address, with optional filtering by token contract. ```php - $ether = new EtherScanService(); - $ether->token_transfer_events_erc1155(); +$ether = new EtherScanService(); +$ether->token_transfer_events_erc1155(); ``` - - Returns the list of blocks mined by an address. ```php - $ether = new EtherScanService(); - $ether->address_blocks_mined(); +$ether = new EtherScanService(); +$ether->address_blocks_mined(); ``` - Returns the balance of an address at a certain block height. - PRO ```php - $ether = new EtherScanService(); - $ether->balance_single_adress(); +$ether = new EtherScanService(); +$ether->balance_single_adress(); ``` - ### Testing ```bash - composer test +composer test ``` ## Credits -- [slvler](https://github.com/slvler) +- [slvler](https://github.com/slvler) ## License From ff165e0eb50af62dc9a7ec40f3b677bbee8b22ea Mon Sep 17 00:00:00 2001 From: slvler <56368718+slvler@users.noreply.github.com> Date: Mon, 21 Oct 2024 00:39:03 +0300 Subject: [PATCH 3/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2b7441a..79bbbaa 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![Latest Stable Version](https://poser.pugx.org/slvler/ether/v)](https://packagist.org/packages/slvler/ether) [![Latest Unstable Version](https://poser.pugx.org/slvler/ether/v/unstable)](https://packagist.org/packages/slvler/ether) [![License](https://img.shields.io/github/license/slvler/etherscan-service)](https://packagist.org/packages/slvler/ether) +[![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether) + An api service for etherscan.io From 8c0f29533587c7d5ac613cc820d4c912d102f8fd Mon Sep 17 00:00:00 2001 From: slvler Date: Mon, 30 Dec 2024 08:09:40 +0300 Subject: [PATCH 4/7] v2.0.0 --- CONTRIBUTING.md | 0 LICENSE => LICENSE.md | 0 README.md | 48 +++++----------------- composer.json | 46 ++++++++++++++------- config/etherscan.php | 5 +-- src/Exception/ErrorException.php | 5 +++ src/Exception/MissingApiKey.php | 15 +++++++ src/Exception/MissingArgumentException.php | 5 +++ src/Resources/Balance.php | 2 +- src/Services/EtherScanService.php | 15 +++++-- 10 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 CONTRIBUTING.md rename LICENSE => LICENSE.md (100%) create mode 100644 src/Exception/ErrorException.php create mode 100644 src/Exception/MissingApiKey.php create mode 100644 src/Exception/MissingArgumentException.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/README.md b/README.md index 79bbbaa..59d0723 100644 --- a/README.md +++ b/README.md @@ -1,132 +1,104 @@ # Etherscan Service - [![tests](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml) -[![Latest Stable Version](https://poser.pugx.org/slvler/ether/v)](https://packagist.org/packages/slvler/ether) -[![Latest Unstable Version](https://poser.pugx.org/slvler/ether/v/unstable)](https://packagist.org/packages/slvler/ether) -[![License](https://img.shields.io/github/license/slvler/etherscan-service)](https://packagist.org/packages/slvler/ether) +[![Latest Stable Version](https://img.shields.io/packagist/v/slvler/ether.svg)](https://packagist.org/packages/slvler/ether) [![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether) - +[![License](https://poser.pugx.org/slvler/ether/license)](https://packagist.org/packages/slvler/ether) An api service for etherscan.io -## Installation +## Requirements +- PHP 8.2 +- Laravel 9.x | 10.x | 11.x +## Installation To install this package tou can use composer: - ```bash composer require slvler/ether ``` ## Usage - - First, you should extract the config/etherscan.php file to the config folder. - ```php php artisan vendor:publish --tag=ether ``` - - 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. - ```php ETHERSCAN_BASE_URL=https://api.etherscan.io/ ETHERSCAN_API_KEY=YOUR-API-KEY ``` - - This is how you can connect to the etherscan api service. - Returns the Ether balance of a given address. - ```php $ether = new EtherScanService(); $ether->balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - - Returns the balance of the accounts from a list of addresses. - ```php $data = [ '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', '0x63a9975ba31b0b9626b34300f7f627147df1f526', '0x198ef1ec325a96cc354c7266a038be8b5c558f67' ]; - $ether = new EtherScanService(); $ether->balance_multiple($data); ``` -- - Returns the list of transactions performed by an address, with optional pagination. - ```php $ether = new EtherScanService(); $ether->transactions_normal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - - Returns the list of internal transactions performed by an address, with optional pagination. - ```php $ether = new EtherScanService(); $ether->transactions_internal('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); ``` - - Returns the list of internal transactions performed within a transaction. - ```php $ether = new EtherScanService(); $ether->transactions_internal_hash('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'); ``` - - Returns the list of internal transactions performed within a block range, with optional pagination. - ```php $ether = new EtherScanService(); $ether->transactions_internal_block_range(); ``` - - Returns the list of ERC-20 tokens transferred by an address, with optional filtering by token contract. - ```php $ether = new EtherScanService(); $ether->token_transfer_events_erc20(); ``` - - Returns the list of ERC-721 ( NFT ) tokens transferred by an address, with optional filtering by token contract. - ```php $ether = new EtherScanService(); $ether->token_transfer_events_erc721(); ``` - - Returns the list of ERC-1155 ( Multi Token Standard ) tokens transferred by an address, with optional filtering by token contract. - ```php $ether = new EtherScanService(); $ether->token_transfer_events_erc1155(); ``` - - Returns the list of blocks mined by an address. - ```php $ether = new EtherScanService(); $ether->address_blocks_mined(); ``` - - Returns the balance of an address at a certain block height. - PRO - ```php $ether = new EtherScanService(); $ether->balance_single_adress(); ``` ### Testing - ```bash composer test ``` ## Credits - - [slvler](https://github.com/slvler) - ## License +The MIT License (MIT). Please see [License File](https://github.com/slvler/etherscan-service/blob/main/LICENSE.md) for more information. -The MIT License (MIT). Please see [License File](https://github.com/slvler/etherscan-service/blob/main/README.md) for more information. +## Contributing +You're very welcome to contribute. +Please see [CONTRIBUTING](https://github.com/slvler/etherscan-service/blob/main/CONTRIBUTING.md) for details. \ No newline at end of file diff --git a/composer.json b/composer.json index 738ae3e..d55cc14 100644 --- a/composer.json +++ b/composer.json @@ -1,40 +1,56 @@ { "name": "slvler/ether", + "description": "Laravel etherscan.io api service", "license": "MIT", - "description": "An api service for etherscan.io", - "type": "package", + "keywords": [ + "etherscan", + "multichain", + "laravel", + "php" + ], "authors": [ { "name": "slvler", "email": "slvler@proton.me" } ], + "homepage": "https://github.com/slvler/etherscan-service", + "require": { + "php": "^8.2", + "guzzlehttp/guzzle": "^7.2", + "illuminate/support": "^9.0|^10.0|^11.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.6", + "orchestra/testbench": "^7.0", + "phpunit/phpunit": "^9.5.8", + "laravel/pint": "^1.18" + }, "autoload": { "psr-4": { - "slvler\\ether\\": "src/" + "Slvler\\Ether\\": "src/" } }, "autoload-dev": { "psr-4": { - "slvler\\ether\\Tests\\": "tests/" + "Slvler\\Ether\\Tests\\": "tests/" } }, - "require": {}, - "require-dev": { - "orchestra/testbench": "^6.18.0", - "phpunit/phpunit": "^9.5", - "guzzlehttp/guzzle": "^7.0.1" - }, - "scripts": { - "test": "vendor/bin/phpunit tests" - }, "extra": { "laravel": { "providers": [ - "slvler\\ether\\EtherServiceProvider" + "Slvler\\Ether\\EtherServiceProvider" ] } }, - "minimum-stability": "dev", + "scripts": { + "test": "vendor/bin/phpunit tests --colors=always", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage", + "pint": "vendor/bin/pint", + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + }, + "minimum-stability": "stable", "prefer-stable": true } diff --git a/config/etherscan.php b/config/etherscan.php index dc55e2a..22032fb 100644 --- a/config/etherscan.php +++ b/config/etherscan.php @@ -11,8 +11,7 @@ | */ 'ether' => [ - 'etherscan_url' => env('ETHERSCAN_BASE_URL'), - 'etherscan_key' => env('ETHERSCAN_API_KEY'), + 'base_url' => env('ETHERSCAN_BASE_URL'), + 'api_key' => env('ETHERSCAN_API_KEY'), ], - ]; diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php new file mode 100644 index 0000000..a22604a --- /dev/null +++ b/src/Exception/ErrorException.php @@ -0,0 +1,5 @@ +base_url = config('etherscan.ether.etherscan_url'); - $this->api_key = config('etherscan.ether.etherscan_key'); + + $apiKey = config('etherscan.ether.api_key'); + if (empty($apiKey) || ! isset($apiKey)) { + throw MissingApiKey::create(); + } + + $this->base_url = config('etherscan.ether.base_url'); + $this->api_key = $apiKey; $this->client = new \GuzzleHttp\Client( ['base_uri' => $this->base_url] From 62612367be4a23eee453d091f367ed1e2c96d38a Mon Sep 17 00:00:00 2001 From: slvler Date: Mon, 30 Dec 2024 08:13:49 +0300 Subject: [PATCH 5/7] v2.0.1 --- README.md | 3 +-- src/Services/EtherScanService.php | 2 ++ tests/Feature/EtherScanTest.php | 6 +++--- tests/Unit/TestCase.php | 8 +++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 59d0723..bb2af96 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # Etherscan Service [![tests](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/etherscan-service/actions/workflows/tests.yml) [![Latest Stable Version](https://img.shields.io/packagist/v/slvler/ether.svg)](https://packagist.org/packages/slvler/ether) -[![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether) [![License](https://poser.pugx.org/slvler/ether/license)](https://packagist.org/packages/slvler/ether) - +[![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether) An api service for etherscan.io ## Requirements diff --git a/src/Services/EtherScanService.php b/src/Services/EtherScanService.php index c429cdf..29cd38e 100644 --- a/src/Services/EtherScanService.php +++ b/src/Services/EtherScanService.php @@ -8,7 +8,9 @@ class EtherScanService { private $base_url; + private $api_key; + private $client; public function __construct() diff --git a/tests/Feature/EtherScanTest.php b/tests/Feature/EtherScanTest.php index f424e27..1ff9dad 100644 --- a/tests/Feature/EtherScanTest.php +++ b/tests/Feature/EtherScanTest.php @@ -1,9 +1,9 @@ Date: Mon, 30 Dec 2024 05:15:21 +0000 Subject: [PATCH 6/7] Apply fixes from StyleCI --- src/Exception/ErrorException.php | 4 +++- src/Exception/MissingArgumentException.php | 4 +++- src/Services/EtherScanService.php | 1 - tests/Unit/TestCase.php | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php index a22604a..f8c6e68 100644 --- a/src/Exception/ErrorException.php +++ b/src/Exception/ErrorException.php @@ -2,4 +2,6 @@ namespace Slvler\Ether\Exception; -class ErrorException {} +class ErrorException +{ +} diff --git a/src/Exception/MissingArgumentException.php b/src/Exception/MissingArgumentException.php index f166c28..2bf742a 100644 --- a/src/Exception/MissingArgumentException.php +++ b/src/Exception/MissingArgumentException.php @@ -2,4 +2,6 @@ namespace Slvler\Ether\Exception; -class MissingArgumentException {} +class MissingArgumentException +{ +} diff --git a/src/Services/EtherScanService.php b/src/Services/EtherScanService.php index 29cd38e..5646f4b 100644 --- a/src/Services/EtherScanService.php +++ b/src/Services/EtherScanService.php @@ -15,7 +15,6 @@ class EtherScanService public function __construct() { - $apiKey = config('etherscan.ether.api_key'); if (empty($apiKey) || ! isset($apiKey)) { throw MissingApiKey::create(); diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 13e5b25..9b4da29 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -18,5 +18,7 @@ protected function getPackageProviders($app) ]; } - protected function getEnvironmentSetUp($app) {} + protected function getEnvironmentSetUp($app) + { + } } From c5d630f16916a1d208231cd5afccee9bafce1633 Mon Sep 17 00:00:00 2001 From: slvler <56368718+slvler@users.noreply.github.com> Date: Mon, 30 Dec 2024 08:16:26 +0300 Subject: [PATCH 7/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb2af96..c12de13 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Latest Stable Version](https://img.shields.io/packagist/v/slvler/ether.svg)](https://packagist.org/packages/slvler/ether) [![License](https://poser.pugx.org/slvler/ether/license)](https://packagist.org/packages/slvler/ether) [![Total Downloads](https://poser.pugx.org/slvler/ether/downloads)](https://packagist.org/packages/slvler/ether) + An api service for etherscan.io ## Requirements @@ -100,4 +101,4 @@ The MIT License (MIT). Please see [License File](https://github.com/slvler/ether ## Contributing You're very welcome to contribute. -Please see [CONTRIBUTING](https://github.com/slvler/etherscan-service/blob/main/CONTRIBUTING.md) for details. \ No newline at end of file +Please see [CONTRIBUTING](https://github.com/slvler/etherscan-service/blob/main/CONTRIBUTING.md) for details.