Skip to content

Commit 17ba654

Browse files
committed
add demo implementation for usage with smart contracts
1 parent 18ee5ac commit 17ba654

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Workbench\App\Console\Commands;
4+
5+
use Farbcode\LaravelEvm\Facades\LaravelEvm;
6+
use Farbcode\LaravelEvm\Facades\EvmLogs;
7+
use Farbcode\LaravelEvm\Support\LogFilterBuilder;
8+
use Illuminate\Console\Command;
9+
10+
class EvmCallCommand extends Command
11+
{
12+
protected $signature = 'evmtest:test';
13+
14+
protected $description = 'Simple Smart Contract interaction test';
15+
16+
public function handle(): int
17+
{
18+
$abiPath = storage_path('app/abi/HelloWorld.abi.json');
19+
if (!file_exists($abiPath)) {
20+
$this->error('ABI file missing: ' . $abiPath);
21+
return self::FAILURE;
22+
}
23+
$abi = file_get_contents($abiPath);
24+
$contract = LaravelEvm::at('0x370E67feF90F06fD3fAB7B7B41d9BFAEd01329A9', $abi);
25+
26+
$result = $contract->call('message');
27+
$this->info('Raw: ' . $result->raw());
28+
$this->info('String: ' . $result->as('string'));
29+
30+
$jobId = $contract->sendAsync("update", ['Hello from Laravel EVM!']);
31+
$this->info('jobId: ' . $jobId);
32+
33+
/* $logs = EvmLogs::query()
34+
->fromBlock(18_000_000)
35+
->eventByAbi($abi, 'Transfer')
36+
->get();
37+
38+
dump($logs);
39+
*/
40+
41+
//$decoded = array_map(fn($l) => LogFilterBuilder::decodeEvent($abi, $l), $logs);
42+
//dump($decoded);
43+
44+
return 1;
45+
}
46+
}

workbench/app/Providers/WorkbenchServiceProvider.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
namespace Workbench\App\Providers;
44

5+
use Farbcode\LaravelEvm\Events\CallPerformed;
6+
use Farbcode\LaravelEvm\Events\TxBroadcasted;
7+
use Farbcode\LaravelEvm\Events\TxFailed;
8+
use Farbcode\LaravelEvm\Events\TxMined;
9+
use Farbcode\LaravelEvm\Events\TxQueued;
10+
use Farbcode\LaravelEvm\Events\TxReplaced;
11+
use Illuminate\Support\Facades\Event;
12+
use Illuminate\Support\Facades\Log;
513
use Illuminate\Support\ServiceProvider;
614

715
class WorkbenchServiceProvider extends ServiceProvider
@@ -19,6 +27,56 @@ public function register(): void
1927
*/
2028
public function boot(): void
2129
{
22-
//
30+
// Log read calls
31+
Event::listen(CallPerformed::class, function (CallPerformed $e) {
32+
Log::info('EVM CallPerformed', [
33+
'address' => $e->address,
34+
'function' => $e->function,
35+
'args' => $e->args,
36+
'rawResult' => $e->rawResult,
37+
]);
38+
});
39+
40+
// Log when transaction is queued
41+
Event::listen(TxQueued::class, function (TxQueued $e) {
42+
Log::info('EVM TxQueued', [
43+
'to' => $e->to,
44+
'data' => $e->data,
45+
]);
46+
});
47+
48+
// Log when transaction broadcasted
49+
Event::listen(TxBroadcasted::class, function (TxBroadcasted $e) {
50+
Log::info('EVM TxBroadcasted', [
51+
'txHash' => $e->txHash,
52+
'fields' => $e->fields,
53+
]);
54+
});
55+
56+
// Log when transaction mined
57+
Event::listen(TxMined::class, function (TxMined $e) {
58+
Log::info('EVM TxMined', [
59+
'txHash' => $e->txHash,
60+
'receipt' => $e->receipt,
61+
]);
62+
});
63+
64+
// Log replacement attempts
65+
Event::listen(TxReplaced::class, function (TxReplaced $e) {
66+
Log::info('EVM TxReplaced', [
67+
'oldTxHash' => $e->oldTxHash,
68+
'attempt' => $e->attempt,
69+
'newFields' => $e->newFields,
70+
]);
71+
});
72+
73+
// Log failures
74+
Event::listen(TxFailed::class, function (TxFailed $e) {
75+
Log::warning('EVM TxFailed', [
76+
'to' => $e->to,
77+
'data' => $e->data,
78+
'reason' => $e->reason,
79+
]);
80+
});
2381
}
2482
}

workbench/bootstrap/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
->withMiddleware(function (Middleware $middleware) {
1515
//
1616
})
17+
->withEvents()
18+
->withProviders()
1719
->withExceptions(function (Exceptions $exceptions) {
1820
//
1921
})->create();

0 commit comments

Comments
 (0)