Laravel Ethereum Module is a Laravel package for work with cryptocurrency Ethereum, with the support ERC-20 tokens. It allows you to generate HD wallets using mnemonic phrase, validate addresses, get addresses balances and resources, preview and send ETH/ERC-20 tokens. You can automate the acceptance and withdrawal of cryptocurrency in your application.
You can contact me for help in integrating payment acceptance into your project.
The following versions of PHP are supported by this version.
- PHP 8.2 and higher
- Laravel 11 or higher
- PHP Extensions: GMP, BCMath, CType.
You can install the package via composer:
composer require sakoora0x/laravel-ethereum-moduleAfter you can run installer using command:
php artisan ethereum:installAnd run migrations:
php artisan migrateRegister Service Provider and Facade in app, edit config/app.php:
'providers' => ServiceProvider::defaultProviders()->merge([
...,
\sakoora0x\LaravelEthereumModule\EthereumServiceProvider::class,
])->toArray(),
'aliases' => Facade::defaultAliases()->merge([
...,
'Ethereum' => \sakoora0x\LaravelEthereumModule\Facades\Ethereum::class,
])->toArray(),For Laravel 10 you edit file app/Console/Kernel in method schedule(Schedule $schedule) add:
$schedule->command('ethereum:sync')
->everyMinute()
->runInBackground();or for Laravel 11+ add this content to routes/console.php:
use Illuminate\Support\Facades\Schedule;
...
Schedule::command('ethereum:sync')
->everyMinute()
->runInBackground();First you need to add Ethereum Nodes, you can register account in ANKR.COM get take HTTPS Endpoint with API key for Ethereum blockchain:
use \sakoora0x\LaravelEthereumModule\Facades\Ethereum;
Ethereum::createNode('My node', 'https://rpc.ankr.com/eth/{API_KEY}');Second you need add Ethereum Explorer, you can register account in Etherscan.io API and take Endpoint with API key:
use \sakoora0x\LaravelEthereumModule\Facades\Ethereum;
Ethereum::createExplorer('My explorer', 'https://api.etherscan.io/api', '{API_KEY}');You can create ERC-20 Token:
use \sakoora0x\LaravelEthereumModule\Facades\Ethereum;
$contractAddress = '0xdac17f958d2ee523a2206206994597c13d831ec7';
Ethereum::createToken($contractAddress);Now you can create new Wallet:
use \sakoora0x\LaravelEthereumModule\Facades\Ethereum;
$wallet = Ethereum::createWallet('My wallet');The package includes a comprehensive test suite covering all major functionality.
Install dev dependencies:
composer install --devRun the test suite:
composer testOr run tests directly with PHPUnit:
vendor/bin/phpunitRun tests with coverage report:
composer test-coverageThe test suite includes tests for:
- Mnemonic generation and validation (12, 15, 18 word phrases)
- HD wallet creation and management
- Address generation and validation
- Checksum address conversion
- Private key to address conversion
- Password encryption and wallet security
- Model relationships and database operations
- Service provider registration
- Configuration loading
For more details about testing, see tests/README.md.
