PHP code example of dappstatus / geth-php

1. Go to this page and download the library: Download dappstatus/geth-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/ */

    

dappstatus / geth-php example snippets


$geth = new \dappstatus\Geth\JsonRpc([
        // Geth JSON-RPC version
        'version' => '2.0',
        // Host part of address
        'host' => '127.0.0.1',
        // Port part of address
        'port' => 8545,
        // Return results as associative arrays instead of objects
        'assoc' => true,
]);

$version = $geth->web3_getVersion();

$accounts = $geth->eth_accounts();
foreach($accounts as $account) {
    echo $account, ': ', $geth->eth_getBalance($account, 'latest'), PHP_EOL;
}

JsonRpc::setOptions([
        // Geth JSON-RPC version
        'version' => '2.0',
        // Host part of address
        'host' => '127.0.0.1',
        // Port part of address
        'port' => 8545,
        // Return results as associative arrays instead of objects
        'assoc' => true,
]);

$version = JsonRpc::web3_getVersion();
    
$accounts = JsonRpc::eth_accounts();
foreach($accounts as $account) {
    echo $account, ': ', JsonRpc::eth_getBalance($account, 'latest'), PHP_EOL;
}