Skip to content

Commit 611db9c

Browse files
committed
Merge commit '5c5a9878d89db6b9531edb4c13b39ee1bbf9d507'
2 parents 1556804 + 5c5a987 commit 611db9c

File tree

2 files changed

+105
-9
lines changed

2 files changed

+105
-9
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All information on how to use this package can be found on our official document
2525
[→ Read the Docs](https://laravel-evm.farbcode.net)
2626

2727
## Requirements
28+
2829
- PHP >= 8.4
2930
- Laravel >= 12
3031
- GMP PHP extension installed and enabled
@@ -62,16 +63,18 @@ $contract = LaravelEvm::at('0xYourContract', $abi);
6263
// Read call
6364
$balance = $contract->call('balanceOf', ['0xUser']);
6465

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

6970
Wait for a known tx hash:
71+
7072
```php
7173
$receipt = $contract->wait('0xTxHash');
7274
```
7375

7476
### Log Filtering & Event Decoding
77+
7578
```php
7679
use Farbcode\LaravelEvm\Facades\EvmLogs;
7780
use Farbcode\LaravelEvm\Support\LogFilterBuilder;

docs/pages/basic-usage.md

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
11
# Basic Usage
22

3-
This page provides the minimal steps to read (eth_call) and write (async EIP-1559) contract functions using the Laravel EVM package. For events, log filtering and full API details see the Advanced Usage and Reference pages.
3+
This page provides the minimal steps to read (eth_call) and write (async EIP-1559) contract functions using the Laravel
4+
EVM package. For events, log filtering and full API details see the Advanced Usage and Reference pages.
45

56
## Contract Handle
7+
68
```php
79
$abi = file_get_contents(base_path('abi/ERC20.json'));
810
$contract = \Farbcode\LaravelEvm\Facades\Evm::at('0xTokenAddress', $abi);
911
```
12+
1013
Obtain a reusable handle for subsequent calls.
1114

1215
## Reads (eth_call)
16+
1317
```php
1418
$symbol = $contract->call('symbol')->as('string');
1519
$balanceHex = $contract->call('balanceOf', ['0xUser']);
1620
$balance = $balanceHex->as('uint');
1721
```
22+
1823
Reads are synchronous and return a `CallResult` wrapper for convenience decoding.
1924

2025
### Decoding Convenience
26+
2127
Any raw hex result from `call()` is wrapped in `CallResult`. Supported `as()` types:
28+
2229
- `string`, `bytes`
2330
- `uint`, `uint256`
2431
- `int`, `int256`
2532
- `bool`
2633
- `address`
2734

2835
Example:
36+
2937
```php
3038
$name = $contract->call('name')->as('string');
3139
$totalSupply = $contract->call('totalSupply')->as('uint256');
3240
$isPaused = $contract->call('paused')->as('bool');
3341
```
42+
3443
If you need the original hex use `->raw()` or cast to string.
3544

3645
#### Error Handling for Reads
46+
3747
A revert during `eth_call` generally yields an empty or error RPC response; you can catch exceptions around the facade:
48+
3849
```php
3950
try {
4051
$value = $contract->call('someFn');
4152
} catch (\Throwable $e) {
4253
// Log & fallback
4354
}
4455
```
56+
4557
Reads should not emit failure events; only `CallPerformed` is emitted on success.
4658

4759
## Writes (Async Transactions)
60+
4861
```php
4962
$requestId = $contract->sendAsync('transfer', ['0xRecipient', 1000]);
5063
```
51-
Writes enqueue a `SendTransaction` job. You need a running queue worker for progress (unless using the sync queue driver).
64+
65+
Writes enqueue a `SendTransaction` job. You need a running queue worker for progress (unless using the sync queue
66+
driver).
5267

5368
### Transaction Job Lifecycle
69+
5470
The queued job executes these steps:
71+
5572
1. ABI encode function + args.
5673
2. Gas estimation with padding.
5774
3. Nonce retrieval (preventing collisions).
@@ -60,32 +77,108 @@ The queued job executes these steps:
6077
6. Broadcast to RPC.
6178
7. Receipt polling until mined or timeout.
6279
8. Optional fee bump & replacement attempts.
63-
Events provide visibility: `TxQueued`, `TxBroadcasted`, `TxReplaced`, `TxMined`, `TxFailed`.
80+
Events provide visibility: `TxQueued`, `TxBroadcasted`, `TxReplaced`, `TxMined`, `TxFailed`.
6481

6582
#### Common Write Pitfalls
83+
6684
- Stuck Pending: Increase priority fee.
6785
- Nonce Errors: Ensure only one worker per signing address.
6886

69-
## Gas Estimation
87+
### Queue Configuration & Workers
88+
89+
By default outgoing transactions are placed on the queue name defined in `config/evm.php` (config('evm.tx.queue'), .env:
90+
`EVM_QUEUE`, default: `evm-send`). Ensure your `QUEUE_CONNECTION` (recommended: `redis`) is configured.
91+
92+
If you set the queue driver to `sync`, jobs execute inline and no worker is required. This is acceptable for local
93+
experiments but not recommended in production (no concurrency control, risk of nonce clashes, blocking HTTP requests).
94+
95+
Start a dedicated worker for the send queue:
96+
97+
```bash
98+
php artisan queue:work --queue=evm-send
99+
```
100+
101+
**CRITICAL: Run exactly ONE worker process per signing address for the `evm-send` queue.** This guarantees strict nonce ordering. Multiple concurrent workers sharing the same private key will race nonces.
102+
If you require higher throughput, add additional signing addresses rather than scaling processes for a single key.
103+
104+
### Horizon Example
105+
106+
When using Laravel Horizon, configure a separate supervisor for `evm-send`:
107+
70108
```php
71-
$data = $contract->call('symbol')->raw(); // Example encoded data reuse
72-
$gas = $contract->estimateGas($data);
109+
// config/horizon.php (excerpt)
110+
return [
111+
'defaults' => [
112+
// ...
113+
114+
'supervisor-2' => [
115+
'connection' => 'redis',
116+
'queue' => ['evm-send'],
117+
'balance' => 'auto',
118+
'autoScalingStrategy' => 'time',
119+
'maxProcesses' => 1, // DO NOT raise for same signer; keep 1 to preserve nonce ordering
120+
'maxTime' => 0,
121+
'maxJobs' => 0,
122+
'memory' => 128,
123+
'tries' => 1,
124+
'timeout' => 180,
125+
'nice' => 0,
126+
],
127+
],
128+
'environments' => [
129+
'production' => [
130+
// ...
131+
'supervisor-2' => [
132+
'maxProcesses' => 1,
133+
],
134+
],
135+
'local' => [
136+
// ...
137+
'supervisor-2' => [
138+
'maxProcesses' => 1,
139+
],
140+
],
141+
],
142+
];
73143
```
74-
Adds configurable padding to avoid underestimation.
144+
Production can scale the default queue separately while keeping `evm-send` serialized.
145+
146+
### Debugging Writes
147+
148+
If a transaction never appears:
149+
150+
- Verify worker running (`queue:work --queue=evm-send`).
151+
- Check emitted events order.
152+
- Inspect RPC responses (enable verbose logging around `eth_sendRawTransaction`).
153+
- Confirm chain ID and private key match network.
154+
- Bump priority fee.
155+
156+
### Waiting for Receipt
75157

76-
## Waiting for Receipt
77158
```php
78159
$receipt = $contract->wait('0xTxHash');
79160
if ($receipt) {
80161
// success
81162
}
82163
```
164+
83165
Wait uses polling; no fee replacement logic here.
84166

167+
## Gas Estimation
168+
169+
```php
170+
$data = $contract->call('symbol')->raw(); // Example encoded data reuse
171+
$gas = $contract->estimateGas($data);
172+
```
173+
174+
Adds configurable padding to avoid underestimation.
175+
85176
## Raw RPC
177+
86178
```php
87179
$block = \Farbcode\LaravelEvm\Facades\EvmRpc::call('eth_blockNumber');
88180
```
181+
89182
Direct access for diagnostics or unsupported methods.
90183

91184
Proceed to Advanced Usage for log filtering and custom components.

0 commit comments

Comments
 (0)