Getting Started
Install the Laravel package, configure your environment, and make your first API call in minutes.
Requirements
| Requirement | Version |
|---|---|
| PHP | 8.1 or higher |
| Laravel | 10.x or 11.x |
| Composer | 2.x |
| ext-json | bundled with PHP 8.x |
| guzzlehttp/guzzle | ^7.0 (auto-installed) |
Installation
Step 1 — Install via Composer
composer require web3sdk/laravel
Step 2 — Publish the config file
php artisan vendor:publish --tag=web3api-config
This creates config/web3api.php in your Laravel app.
Step 3 — Add environment variables
WEB3_API_KEY=ak_live_xxxxxxxxxx
WEB3_DEFAULT_NETWORK=polygon
Create your API key in the provider dashboard (Dashboard → API Keys). The API endpoint is built into the SDK — no URL configuration needed.
Step 4 — Use the Facade
The Web3Api facade is automatically registered by the ServiceProvider. No manual registration needed.
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
$balance = Web3Api::balance()->getNative(address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
// ['balance' => '1.5', 'symbol' => 'MATIC', 'network' => 'polygon', ...]
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
WEB3_API_KEY |
Yes | — | Your API key (ak_live_xxx), created in the provider dashboard. The SDK throws on boot if missing. |
WEB3_DEFAULT_NETWORK |
No | polygon |
Default network used when no $network argument is passed to module methods. |
WEB3_TIMEOUT |
No | 30 |
HTTP request timeout in seconds. |
Authentication
Every request authenticates with your API key — sent automatically as the X-Api-Key header. Account login, key management, package purchase, and webhooks all live in the provider dashboard, not in this SDK.
<?php
// config/web3api.php is already populated via .env
// Just use the facade — the API key is sent automatically
use Web3Sdk\Laravel\Facades\Web3Api;
$balance = Web3Api::balance()->getNative(address: '0xABC...');
// Transfers can omit privateKey (pass null) — the API signs with the
// stored managed wallet for the from address.
$tx = Web3Api::transfer()->native(
fromAddress: '0xSENDER...',
privateKey: null,
toAddress: '0xRECEIVER...',
amount: '0.5',
);
With an API Key, the network is bound to the key configuration. You do not need to pass a
$network argument — the key's network is used automatically.Network Resolution
How the API determines which blockchain network to use:
API Key: Network is determined by the key's configuration. The
Plugin default: If
$network parameter is ignored.Plugin default: If
WEB3_DEFAULT_NETWORK is set and no $network arg is passed, the plugin uses that value.
<?php
// Pass network explicitly — overrides .env default
$balance = Web3Api::balance()->getNative(
address: '0xABC...',
network: 'ethereum', // use Ethereum mainnet for this call
);
// Omit network — uses WEB3_DEFAULT_NETWORK (.env)
$balance = Web3Api::balance()->getNative(address: '0xABC...');
Supported Networks
| Network Slug | Full Name | Chain ID | Symbol | Type |
|---|---|---|---|---|
ethereum | Ethereum Mainnet | 1 | ETH | Mainnet |
polygon | Polygon Mainnet | 137 | MATIC | Mainnet |
bsc | BNB Smart Chain | 56 | BNB | Mainnet |
arbitrum | Arbitrum One | 42161 | ETH | Mainnet |
optimism | Optimism | 10 | ETH | Mainnet |
avalanche | Avalanche C-Chain | 43114 | AVAX | Mainnet |
polygon_mumbai | Polygon Mumbai | 80001 | MATIC | Testnet |
goerli | Goerli | 5 | ETH | Testnet |
sepolia | Sepolia | 11155111 | ETH | Testnet |
Fetch the live list of networks (including any newly added ones) at any time:
<?php
$networks = Web3Api::networks()->list();
// Returns array of network objects with chain_id, symbol, explorer_url, is_testnet, etc.