PHP code example of amashukov / eth-rpc-client-php
1. Go to this page and download the library: Download amashukov/eth-rpc-client-php 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/ */
amashukov / eth-rpc-client-php example snippets
use Amashukov\EthRpc\EthRpcClient;
use Amashukov\EthRpc\JsonRpcProvider;
use Amashukov\HttpClient\CurlClient;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\Clock\NativeClock;
$psr17 = new Psr17Factory();
$http = new CurlClient($psr17, $psr17, timeoutSeconds: 30);
$client = new EthRpcClient($http, $psr17, $psr17, 'https://your-eth-node.example/rpc');
$provider = new JsonRpcProvider($client, new NativeClock());
$balanceWei = $provider->getBalance('0xabc...'); // decimal string
$bundle = $provider->getTypedTransaction('0xtxhash'); // EthereumTxBundle
if ($bundle->isStatusSuccess()) {
$gasFee = $bundle->receipt->fee; // decimal wei
}
$fee = $provider->getFeeData(); // EthereumFeeData
$usdt = $provider->getErc20Balance('0xdAC17...', '0xholder...');