๐
๐
Laravel Web3
Laravel Web3 helps you to kickstart your web3 apps.
- No more headache with handling wallet changing address and sync with laravel back-end.
- Just do it
- Really, just do the steps below and be done.
Support this
Investing on Laravel-Web3 is defintely a good move from you. You can support by donating to my wallet
- Wallet 0x3F20d326E5DA8ab6D27d9b2DdD350baB1e589d87
- PayPal https://www.paypal.com/paypalme/sawirricardo.
Installation
You can install the package via composer:
composer require sawirricardo/laravel-web3
You can publish and run the migrations with:
php artisan vendor:publish --provider="Sawirricardo\LaravelWeb3\LaravelWeb3ServiceProvider" --tag="laravel-web3-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Sawirricardo\LaravelWeb3\LaravelWeb3ServiceProvider" --tag="laravel-web3-config"
This is the contents of the published config file:
return [
'network' => env('WEB3_NETWORK', 'localhost'),
'infura_id' => env('WEB3_INFURA_ID', ''),
];
Add this to your .env
WEB3_NETWORK=localhost #mainnet, mumbai, etc
WEB_INFURA_ID=xxxxxxxxxxxxxxxxxx
MIX_WEB3_NETWORK="${WEB3_NETWORK}"
MIX_WEB3_INFURA_ID="${WEB_INFURA_ID}"
Then, add "account" to \App\Models\User fillables
// app/Models/User.php
protected $fillable = [
'email','name','password',
'account' //Add this
];
Also add this to your layout HTML
<body>
<!-- it's best to drop this at the below -->
<script
src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
type="application/javascript"
></script>
<script
type="text/javascript"
src="https://unpkg.com/[email protected]/dist/index.js"
></script>
<script
type="text/javascript"
src="https://unpkg.com/@walletconnect/[email protected]/dist/umd/index.min.js"
></script>
<x-laravelweb3Scripts />
</body>
Usage
@guest
<button onclick="laravelWeb3.onConnect()">Connect to wallet</button>
@endguest
@auth
<button onclick="laravelWeb3.onDisconnect()">Disconnect wallet</button>
@endauth
// return provider object by Ethers JS
// Run wild, my friends
const etherProvider = laravelWeb3.getProvider();
// LaravelWeb3 automatically register laravelWeb3 to window object for you to play.
console.log({window.laravelWeb3});
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.