Skip to main content

Write Methods

The write interface sends state-changing transactions via eth_sendTransaction. These calls modify blockchain state and require gas.
This uses the Contract pattern - a copyable implementation you add to your codebase.

Basic Usage

How It Works

When you call a write method:
  1. Encode - Arguments are ABI-encoded with the function selector
  2. Send - eth_sendTransaction is sent to the provider
  3. Return - Transaction hash is returned immediately
Write methods return immediately after the transaction is submitted. The transaction may still be pending or could fail during execution.

Transaction Options

Override transaction parameters:

Payable Functions

For functions that accept ETH, pass value in options:

Error Handling

Write calls can fail at submission or execution:
Common failures:
  • Insufficient funds - Not enough ETH for gas
  • User rejected - User rejected in wallet
  • Nonce too low - Transaction already mined
  • Gas estimation failed - Transaction would revert

Waiting for Confirmation

The write method returns immediately. To wait for confirmation:

Simulating Before Sending

Use estimateGas to simulate the transaction first: