Receipt
The receipt of a mined transaction: whether it succeeded, the gas it used, the logs it emitted and the contract it created.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const hash = "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3";
const outcome = Effect.gen(function* () { const receipt = yield* Eth.getTransactionReceipt(hash); if (receipt === null) return "not mined yet"; // receipt: Receipt.Receipt return `${receipt.status} in block ${receipt.blockNumber}, gas ${receipt.gasUsed}`;});// "success in block 1, gas 21000"Schemas
Section titled “Schemas”| Schema | Type | Describes | Returned by |
|---|---|---|---|
Receipt.schema |
Receipt.Receipt |
a receipt | Eth.getTransactionReceipt, Eth.getBlockReceipts, Eth.sendTransactionSync, Eth.sendRawTransactionSync, Eth.subscribe.transactionReceipts |
Receipt.statusSchema |
Receipt.Status |
"success" or "reverted" |
status of a receipt |
Import a type to name it in your own signatures.
import type { Receipt } from "@ethect/core/rpc";
/** The fee paid, in wei, where the node reports the price. */const feePaid = (receipt: Receipt.Receipt): bigint | undefined => receipt.effectiveGasPrice === undefined ? undefined : receipt.gasUsed * receipt.effectiveGasPrice;Fields
Section titled “Fields”| Field | Type | Notes |
|---|---|---|
transactionHash |
Hash |
|
transactionIndex |
number |
the position of the transaction in its block |
blockHash |
Hash |
|
blockNumber |
bigint |
|
from |
Address |
the sender |
to |
Address | null |
null when the transaction created a contract |
status |
"success" | "reverted" (optional) |
absent before Byzantium |
root |
Hash (optional) |
the state root after the transaction, before Byzantium only |
type |
Transaction.Type or a Hex (optional) |
the type of the transaction |
contractAddress |
Address (optional) |
the contract the transaction created |
gasUsed |
bigint |
the gas this transaction used |
cumulativeGasUsed |
bigint |
the gas used in the block up to and including this transaction |
effectiveGasPrice |
bigint (optional) |
the price paid per gas, in wei. Absent from a node that does not report it. |
blobGasUsed |
bigint (optional) |
on a transaction that carries blobs |
blobGasPrice |
bigint (optional) |
on a transaction that carries blobs |
logs |
ReadonlyArray<Log> |
the logs the transaction emitted |
logsBloom |
Hex |
Behavior
Section titled “Behavior”- A status is a name. The node sends
"0x1"or"0x0"and you read"success"or"reverted". The code is matched by value:"0x01"is"success"too. effectiveGasPricecan be absent. A node that leaves it out or sendsnullgives a receipt without the key. anvil and current clients send it.- A reverted transaction has a receipt. It was mined and paid for its gas. Only
statustells it from a successful one. contractAddressis absent, notnull. A node sendsnullwhen no contract was created, and the key is then left out of the object. Test it withreceipt.contractAddress !== undefined.toisnullfor a creation. The same receipt then has acontractAddress.- No receipt while pending. A method that looks a receipt up returns
nulluntil the transaction is mined: there is no pending form of this type. - Numbers. Gas and prices are
bigint.transactionIndexis anumber. See values on the wire.