1. Go to this page and download the library: Download edgaras/ethereum 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/ */
edgaras / ethereum example snippets
use Edgaras\Ethereum\Ethereum;
use Edgaras\Ethereum\Wallet;
$rpcUrl = 'https://sepolia.infura.io/v3/API_KEY';
$chainId = 11155111; // Sepolia
$eth = new Ethereum($rpcUrl, $chainId);
// Create a new wallet (or import with new Wallet('0x...'))
$wallet = $eth->createWallet();
$eth->setWallet($wallet);
echo "Address: {$wallet->getAddress()}<br>";
echo "Private Key: {$wallet->getPrivateKeyHex()}<br>";
// Get balance (ETH)
echo "Balance: {$eth->getBalanceInEther()} ETH<br>";
use Edgaras\Ethereum\Ethereum;
use Edgaras\Ethereum\Wallet;
$eth = new Ethereum($rpcUrl, $chainId);
$eth->setWallet(new Wallet('0xYOUR_PRIVATE_KEY_HEX'));
$txHash = $eth->sendEther('0xRecipientAddress...', '0.01');
echo "tx: $txHash<br>";
// (optional) wait for confirmation
$receipt = $eth->waitForConfirmation($txHash, maxAttempts: 60, delaySeconds: 2);
echo "
use Edgaras\Ethereum\Ethereum;
use Edgaras\Ethereum\Wallet;
use Edgaras\Ethereum\Utils;
$eth = new Ethereum($rpcUrl, $chainId);
$eth->setWallet(new Wallet('0xYOUR_PRIVATE_KEY_HEX'));
// Set EIP-1559 gas parameters (in gwei)
$maxPriorityFeePerGasGwei = '2'; // 2 gwei tip
$maxFeePerGasGwei = '20'; // 20 gwei max fee
// Convert to wei hex
$maxPriorityFeePerGas = Utils::toHex(Utils::gweiToWei($maxPriorityFeePerGasGwei));
$maxFeePerGas = Utils::toHex(Utils::gweiToWei($maxFeePerGasGwei));
$txHash = $eth->sendEtherEIP1559(
'0xRecipientAddress...',
'0.01',
$maxFeePerGas,
$maxPriorityFeePerGas
);
echo "EIP-1559 tx: $txHash<br>";
// Legacy (Type-0): uses gasPrice
public function sendEther(string $to, string $amount, array $options = []): string
// EIP-1559 (Type-2): uses dynamic fees
public function sendEtherEIP1559(
string $to,
string $amount,
string $maxFeePerGas, // hex wei, e.g. '0x4a817c800' (20 gwei)
string $maxPriorityFeePerGas, // hex wei, e.g. '0x77359400' (2 gwei)
array $options = []
): string