Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
PHP
web3.php is the primary PHP library for talking to the Avalanche C-Chain over JSON-RPC — a good fit for adding AVAX balance lookups or transaction submission to an existing PHP backend at chain ID 43114. Install it with composer require web3p/web3.php. The library uses a callback-based API, where each call hands you ($err, $result), so wrap those calls in a dedicated service class to keep the callback nesting out of your controllers.
web3.php exposes a callback-based API: every C-Chain method takes a closure that receives the error and the result. In a Laravel app, push that pattern into an injectable service class so your controllers stay thin and the Avalanche RPC details live in one place.
Web3.php
Instantiate the client by chaining the providers: new Web3(new HttpProvider(new HttpRequestManager('https://avalanche.therpc.io/YOUR_API_KEY'))). Every eth method then takes a callback of the form function ($err, $result). Always check $err first and only touch $result when it is null — a C-Chain RPC error or a network hiccup arrives through $err, not as a thrown exception.
<?php
use Web3\Web3;
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\HttpRequestManager;
class EthereumService
{
private $web3;
public function __construct()
{
$this->web3= new Web3(new HttpProvider(new HttpRequestManager('https://avalanche.therpc.io/YOUR_API_KEY')));
}
public function getBalance(string $address): string
{
$balance = null;
$this->web3->eth->getBalance($address, 'latest', function ($err, $result) use (&$balance) {
Key features: JSON-RPC support for the Avalanche C-Chain, contract interactions, transaction handling, wei/AVAX unit conversion, and ABI encoding/decoding
Laravel Integration
In Laravel, keep the C-Chain endpoint out of your source by reading it from config('services.ethereum.node_url'), backed by an .env entry pointing at https://avalanche.therpc.io/YOUR_API_KEY. Wrap balance lookups in Cache::remember so repeated requests for the same address are served from cache instead of hitting the Avalanche endpoint on every page load — a short TTL keeps values fresh given the chain's fast block times while cutting redundant RPC traffic.
<?php
namespace App\Services;
use Web3\Web3;
use Illuminate\Support\Facades\Cache;
class EthereumService
{
private $web3;
public function __construct()
{
$this->web3= new Web3(config('services.ethereum.node_url'));
}
public function getCachedBalance(string $address): string
{
return Cache::remember("eth_balance_{$address}", 300, function () use ($address) {
return $this->getBalance($address);
});
}
public function getTransactionCount(string $address): int
{
$count = null;
$this->web3->eth->getTransactionCount($address, 'latest', function ($err, $result) use (&$count) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$count = hexdec($result);
});
return $count;
}
}
Smart Contract Integration
For contract calls, use the Contract class from web3.php: construct it with the provider and ABI, then point it at the deployed C-Chain address with ->at($contractAddress). Invoke read-only methods with ->call($method, $params, $callback), where the callback receives ($err, $response) — the same convention as the core eth methods, so error handling stays consistent across your service.
<?php
use Web3\Contract;
class SmartContractService
{
private $contract;
public function __construct(string $abi, string $contractAddress)
{
$web3= new Web3(new HttpProvider(new HttpRequestManager('https://avalanche.therpc.io/YOUR_API_KEY')));
$this->contract = new Contract($web3->provider, $abi);
$this->contract->at($contractAddress);
}
public function callMethod(string $method, array $params = [])
{
$result = null;
$this->contract->call($method, $params, function ($err, $response) use (&$result) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$result = $response;
});
return $result;
}
}
Error Handling
Because web3.php surfaces failures through callback $err values, it helps to normalize them into a single domain exception. Define an EthereumException that wraps the original error and rethrow it from your service methods, so callers across the app can catch one type for any C-Chain failure — a reverted transaction, an invalid address, or an unreachable endpoint.
<?php
class EthereumException extends Exception
{
private $ethError;
public function __construct(string $message, $ethError = null)
{
parent::__construct($message);
$this->ethError = $ethError;
}
public function getEthError()
{
return $this->ethError;
}
}
class SafeEthereumService
{
public function safeGetBalance(string $address): string