Skip to content

Events

Transactional events provide lifecycle visibility for asynchronous writes. Use them for logging, metrics, user notifications, and fee escalation monitoring.

Event List

EventWhen FiredKey FieldsPurpose
TxQueuedJob dispatchedrequest_id, function, addressTrack submission before broadcast
TxBroadcastedFirst raw tx acceptedtx_hash, nonce, feesPersist hash, start monitoring
TxReplacedReplacement broadcastold_tx_hash, new_tx_hash, attempt, feesFee bump / speed-up diagnostics
TxMinedReceipt obtainedtx_hash, receiptSuccess; update state models
TxFailedTerminal failurereason, attemptsAlert; possible manual intervention
CallPerformedRead call completedfrom, to, function, raw_resultAuditing read queries

Example Listener Registration

php
protected $listen = [
    \Farbcode\LaravelEvm\Events\TxMined::class => [\App\Listeners\NotifyUser::class],
    \Farbcode\LaravelEvm\Events\TxFailed::class => [\App\Listeners\AlertDevTeam::class],
];

Sample Listener

php
namespace App\Listeners;

use Farbcode\LaravelEvm\Events\TxBroadcasted;
use Illuminate\Support\Facades\Log;

class LogTxBroadcasted
{
    public function handle(TxBroadcasted $e): void
    {
        Log::info('TX broadcasted', [
            'hash' => $e->txHash,
            'nonce' => $e->nonce,
            'fees' => $e->fees,
        ]);
    }
}

Fee Bump Strategy

When a tx has not mined within confirm_timeout, and max_replacements not exceeded:

  1. Policy recalculates higher fees.
  2. Replacement signed & broadcast.
  3. TxReplaced emitted.

Tune in config/evm.php:

php
'tx' => [
  'confirm_timeout' => 120,      // seconds before considering replacement
  'max_replacements' => 2,        // number of bumps allowed
  'poll_interval_ms' => 800,      // receipt poll delay
]

Observability Tips

  • Measure time from TxQueued to TxMined for performance SLA.
  • Count replacements to detect fee configuration issues.
  • Alert on frequent identical TxFailed reasons (RPC or gas problems).
  • Log priority fee deltas between attempts.

Debug Flow Example

TxQueued -> TxBroadcasted -> (TxReplaced)* -> TxMined | TxFailed

Parenthesis denotes zero or more replacements.

Handling Failures

On TxFailed, inspect reason:

  • Gas estimation failure: review contract & args.
  • Broadcast rejection: fees or nonce invalid.
  • Timeout without receipt: consider manual bump or external explorer check.

Released under the MIT License.