1. Go to this page and download the library: Download roberts/web3-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Roberts\Web3Laravel\Models\Wallet;
use Roberts\Web3Laravel\Models\Contract;
$wallet = Wallet::first();
$balance = $wallet->balance(); // getBalance()
$nonce = $wallet->nonce(); // getTransactionCount()
$gas = $wallet->gasPrice(); // getGasPrice()
// Estimate gas for a potential transaction from this wallet
$estimatedGasHex = $wallet->estimateGas([
'to' => '0x0000000000000000000000000000000000000000',
'value' => 1000,
// 'data' => '0x...', // optional
]);
// Send a transaction (legacy fields; signing library
use App\Models\User;
use Roberts\Web3Laravel\Models\Wallet;
$user = User::first();
// Create a wallet and associate to a user
$wallet = Wallet::create([
'address' => '0x...',
'key' => '0x...', // will be encrypted by the model mutator
'owner_id' => $user->id,
]);
// Or via the service (recommended): generates keys and sets owner automatically
$wallet = app(Roberts\Web3Laravel\Services\WalletService::class)
->create([], $user);
// Access the owner and query by owner
$owner = $wallet->user; // belongsTo the configured auth user model
$wallets = Wallet::forUser($user)->get();