PHP code example of farbcode / laravel-evm

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

    

farbcode / laravel-evm example snippets


use Farbcode\LaravelEvm\Facades\Evm;

$abi = file_get_contents(storage_path('app/abi/MyContract.abi.json'));
$contract = LaravelEvm::at('0xYourContract', $abi);

// Read call
$balance = $contract->call('balanceOf', ['0xUser']);

// Write (async - enqueued on EVM_QUEUE default:evm-send, see https://laravel-evm.farbcode.net/basic-usage#writes-async-transactions for more information)
$jobId = $contract->sendAsync('transfer', ['0xRecipient', 100]);

$receipt = $contract->wait('0xTxHash');

use Farbcode\LaravelEvm\Facades\EvmLogs;
use Farbcode\LaravelEvm\Support\LogFilterBuilder;

$abi = file_get_contents(storage_path('app/abi/ERC20.abi.json'));
$logs = EvmLogs::query()
    ->fromBlock(18_000_000)
    ->toBlock('latest')
    ->address('0xToken')
    ->eventByAbi($abi, 'Transfer')
    ->topicAny(1, [LogFilterBuilder::padAddress($addrA), LogFilterBuilder::padAddress($addrB)])
    ->get();
$decoded = array_map(fn($l) => LogFilterBuilder::decodeEvent($abi, $l), $logs);
bash
php artisan vendor:publish --tag="evm-config"