PHP code example of phpblock / core

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

    

phpblock / core example snippets




reum = new PHPBlock\Network\Ethereum\Client();

$Ethereum->ethProtocolVersion()
    ->then(function (string $version) {
        echo "The protocol version is: " . $version . "\n";
    });

$Ethereum->run();



HPBlock\Network\Ethereum\Model\Gwei;
use PHPBlock\Network\Ethereum\Model\Transaction;
use PHPBlock\Network\Ethereum\Type\Hash32;
use PHPBlock\Network\Ethereum\Type\HexAddress;

use function PHPBlock\Helper\pass;

$Ethereum = new PHPBlock\Network\Ethereum\Client();
# Lightweight types for all data elements.
$value = new Gwei(Gwei::ethToGwei('.0001'));
$to = new HexAddress('0x579ACE666FBbb2cE728B5F335E69Dc7A2C8623D4');
$from = new HexAddress('0x268d5eBe19aF845c23E0Fd4290725E9679Cd1B7d');
$sendTransaction = Transaction::make($to, $from, $value);

$Ethereum->ethSendTransaction($sendTransaction)
    ->then(function (Hash32 $hash32) use ($Ethereum) {
        # Pass additional values easily similar to a tuple.
        return pass($Ethereum->ethGetTransactionByHash($hash32), $hash32);
    })->then(function (array $data) {
        [$receiveTransaction, $hash32] = $data;

        if ($receiveTransaction->hash == $hash32) {
            echo "The hashes match!";
        }
    });

$Ethereum->run();