Laravel Package
web3sdk/laravel
Multi-chain blockchain operations for Laravel — EVM networks, token transfers, NFTs, smart contracts, and more. One Facade, all chains.
Quick Install
Install the package via Composer:
Composer
composer require web3sdk/laravel
Then publish the config file:
php artisan vendor:publish --tag=web3api-config
.env Configuration
Add these variables to your .env file:
WEB3_API_KEY=ak_live_xxxxxxxxxx
WEB3_DEFAULT_NETWORK=polygon
API Key vs JWT: For server-side use (most apps), set
WEB3_API_KEY. The network is bound to the key — no per-request network param needed. See Authentication for when to use JWT instead.Quick-Start Examples
1 — Get native balance
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
// Get MATIC balance on Polygon
$result = Web3Api::balance()->getNative(address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
echo $result['balance']; // "1.5"
echo $result['symbol']; // "MATIC"
echo $result['network']; // "polygon"
2 — Transfer native currency
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
use Web3Sdk\Laravel\Exceptions\InsufficientCreditsException;
use Web3Sdk\Laravel\Exceptions\Web3ApiException;
try {
$tx = Web3Api::transfer()->native(
fromAddress: '0xSENDER...',
privateKey: '0xYOUR_PRIVATE_KEY',
toAddress: '0xRECEIVER...',
amount: '0.1', // 0.1 MATIC
);
echo $tx['tx_hash']; // "0xabc123..."
echo $tx['status']; // "pending"
} catch (InsufficientCreditsException $e) {
echo "Need {$e->cost} credits, have {$e->balance}";
} catch (Web3ApiException $e) {
echo "Error {$e->statusCode}: {$e->getMessage()}";
}
3 — Check NFT ownership
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
// How many tokens does an address hold?
$result = Web3Api::nft()->balance(
contractAddress: '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
ownerAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
);
echo $result['balance']; // 3
// Get info on a specific token
$nft = Web3Api::nft()->info(
contractAddress: '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
tokenId: 42,
);
echo $nft['owner']; // "0xd8dA..."
echo $nft['token_uri']; // "ipfs://..."