Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- `Ethers.Transaction.decode/1` returns `{:error, reason}` instead of raising on malformed input
- Unsigned EIP-155 legacy transactions decode as `%Legacy{}` instead of `%Signed{}`
- All returned addresses are EIP-55 checksummed, including `Ethers.Event` `address` and `Ethers.deployed_address/2`
- `Ethers.get_transaction_receipt/2` returns an `Ethers.Receipt` struct instead of the raw RPC map

### Enhancements

Expand All @@ -23,6 +24,8 @@
- Add `Ethers.get_code/2` (`eth_getCode`)
- Add `Ethers.get_delegation/2` and `Ethers.Authorization.parse_delegation/1` to inspect EIP-7702 delegations
- Warn about gas limits above the [EIP-7825](https://eips.ethereum.org/EIPS/eip-7825) cap, enforce a cap with `:max_transaction_gas`
- Add `Ethers.Receipt` struct with decoded transaction receipt fields
- Add `Ethers.Receipt.decode_logs/2` to decode receipt logs with event filters

### Bug Fixes

Expand All @@ -38,6 +41,7 @@
- Compare the `:signer_opts` `from` address with the transaction `from` case-insensitively
- Fix the `http_options` timeout example in the configuration guide
- Fix `:get_balance` requests in `Ethers.batch/2`
- Fix the `:get_transaction_receipt` action of `Ethers.batch/2`

## 0.8.0 (2026-07-29)

Expand Down
30 changes: 28 additions & 2 deletions guides/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ casing they were configured with:
build

Other returned addresses (ABI-decoded values, transaction `to`, recovered signers, ...) were
already checksummed. Raw RPC values (`topics_raw`, `data_raw`, `Ethers.get_transaction_receipt/2`
maps) are unchanged, and addresses are still accepted in any casing.
already checksummed. Raw RPC values (`topics_raw`, `data_raw`, the `logs` of an `Ethers.Receipt`)
are unchanged, and addresses are still accepted in any casing.

```elixir
{:ok, address} = Ethers.deployed_address(tx_hash)
Expand All @@ -234,6 +234,32 @@ address == Ethers.Utils.to_checksum_address(other_address)
Ethers.Utils.decode_address!(address) == Ethers.Utils.decode_address!(other_address)
```

### Transaction Receipts

#### `get_transaction_receipt/2` returns an `Ethers.Receipt` struct

`Ethers.get_transaction_receipt/2`, `Ethers.get_transaction_receipt!/2` and the
`:get_transaction_receipt` action of `Ethers.batch/2` return an `Ethers.Receipt` struct instead of
the node's JSON map: quantities are integers, `status` is `:success` or `:failure` and addresses are
checksummed. Logs are kept as returned by the node, decode them with
`Ethers.Receipt.decode_logs/2`. Members the library does not decode, such as chain specific
members, are kept undecoded in `extra`. A malformed receipt returns
`{:error, {:invalid_receipt_member, member}}`.

```elixir
{:ok, receipt} = Ethers.get_transaction_receipt(tx_hash)

# Before (0.8.x)
%{"status" => "0x1", "gasUsed" => gas_used_hex, "contractAddress" => contract_address} = receipt
gas_used = Ethers.Utils.hex_to_integer!(gas_used_hex)
l1_fee = receipt["l1Fee"]

# After (1.0.0)
%Ethers.Receipt{status: :success, gas_used: gas_used, contract_address: contract_address} = receipt
l1_fee = receipt.extra["l1Fee"]
events = Ethers.Receipt.decode_logs(receipt, MyContract.EventFilters)
```

## Upgrading to 0.6.x

Version 0.6.x and onwards introduce several breaking changes to improve type safety and explicitness.
Expand Down
33 changes: 30 additions & 3 deletions lib/ethers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defmodule Ethers do
alias Ethers.EventFilter
alias Ethers.ExecutionError
alias Ethers.ForkConfig
alias Ethers.Receipt
alias Ethers.StateOverride
alias Ethers.Transaction
alias Ethers.TxData
Expand Down Expand Up @@ -105,6 +106,7 @@ defmodule Ethers do
get_logs: :eth_get_logs,
get_transaction_count: :eth_get_transaction_count,
get_transaction: :eth_get_transaction_by_hash,
get_transaction_receipt: :eth_get_transaction_receipt,
max_priority_fee_per_gas: :eth_max_priority_fee_per_gas,
send_transaction: :eth_send_transaction,
blob_base_fee: :eth_blob_base_fee,
Expand Down Expand Up @@ -357,16 +359,38 @@ defmodule Ethers do
end

@doc """
Returns the receipt of a transaction by it's hash.
Returns the receipt of a transaction by its hash (`eth_getTransactionReceipt`), decoded to an
`Ethers.Receipt` struct.

The logs of the receipt are kept as returned by the node, decode them with
`Ethers.Receipt.decode_logs/2`. Members the library does not decode, such as chain
specific members, are kept undecoded in the `extra` field.

Also works with `Ethers.batch/2` as `{:get_transaction_receipt, tx_hash}`.

## Parameters
- tx_hash: Transaction hash which the transaction receipt is queried for.
- overrides:
- rpc_client: The RPC module to use for this request (overrides default).
- rpc_opts: Specific RPC options to specify for this request.

## Returns
- `{:ok, receipt}` with an `Ethers.Receipt` struct.
- `{:error, :transaction_receipt_not_found}` if the node has no receipt for the
transaction (unknown or not yet included in a block).
- `{:error, {:invalid_receipt_member, member}}` if the node returned a member that does
not match the receipt schema (e.g. `{:invalid_receipt_member, "status"}`).
- `{:error, reason}` on RPC failures.

## Examples

```elixir
Ethers.get_transaction_receipt("0x9c4e...6e5d")
{:ok, %Ethers.Receipt{status: :success, gas_used: 45029, type: 2, ...}}
```
"""
@spec get_transaction_receipt(Types.t_hash(), Keyword.t()) ::
{:ok, map()} | {:error, term()}
{:ok, Receipt.t()} | {:error, term()}
def get_transaction_receipt(tx_hash, opts \\ []) when is_binary(tx_hash) do
{rpc_client, rpc_opts} = get_rpc_client(opts)

Expand All @@ -377,7 +401,7 @@ defmodule Ethers do
@doc """
Same as `Ethers.get_transaction_receipt/2` but raises on error.
"""
@spec get_transaction_receipt!(Types.t_hash(), Keyword.t()) :: map() | no_return()
@spec get_transaction_receipt!(Types.t_hash(), Keyword.t()) :: Receipt.t() | no_return()
def get_transaction_receipt!(tx_hash, opts \\ []) do
case get_transaction_receipt(tx_hash, opts) do
{:ok, receipt} -> receipt
Expand Down Expand Up @@ -1602,6 +1626,9 @@ defmodule Ethers do
defp post_process({:ok, nil}, _tx_hash, :get_transaction_receipt),
do: {:error, :transaction_receipt_not_found}

defp post_process({:ok, receipt}, _tx_hash, :get_transaction_receipt),
do: Receipt.from_rpc_map(receipt)

defp post_process({:ok, resp}, _data, :fee_history) when is_map(resp) do
{:ok,
%{
Expand Down
Loading
Loading