sawirricardo/laravel-web3

Send your laravel apps to the moon with web3 enabled 🚀

1.0.0 2022-03-15 02:21 UTC

This package is auto-updated.

Last update: 2024-11-15 15:16:30 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

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/web3modal@1.9.0/dist/index.js"
    ></script>
    <script
        type="text/javascript"
        src="https://unpkg.com/@walletconnect/web3-provider@1.6.5/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.