More lookups
The other ways to find a transaction: by its position in a block, by its sender and nonce, in its signed and encoded form, and all those in the pending pool.
| Method | JSON-RPC | Returns | Description |
|---|---|---|---|
getTransactionByBlockNumberAndIndex |
eth_getTransactionByBlockNumberAndIndex |
Transaction | null |
A transaction by its position in a block, by number or tag. |
getTransactionByBlockHashAndIndex |
eth_getTransactionByBlockHashAndIndex |
Transaction | null |
A transaction by its position in a block, by block hash. |
getTransactionBySenderAndNonce |
eth_getTransactionBySenderAndNonce |
Transaction | null |
The transaction an account sent with a given nonce. |
getRawTransactionByHash |
eth_getRawTransactionByHash |
Hex | null |
A transaction in its signed, encoded form, by hash. |
getRawTransactionByBlockNumberAndIndex |
eth_getRawTransactionByBlockNumberAndIndex |
Hex | null |
The same, by position in a block, by number or tag. |
getRawTransactionByBlockHashAndIndex |
eth_getRawTransactionByBlockHashAndIndex |
Hex | null |
The same, by position in a block, by block hash. |
pendingTransactions |
eth_pendingTransactions |
ReadonlyArray<Transaction> |
The transactions in the node’s pending pool. |
Each returns an Effect of the type in the table, which
fails with a Method.Error and needs a Transport. Every lookup of one transaction returns
null when the node finds nothing. To look a transaction up by its hash, use
Eth.getTransactionByHash.
getTransactionByBlockNumberAndIndex
Section titled “getTransactionByBlockNumberAndIndex”Returns the transaction at a position in a block, by the number or tag of the block.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const first = Eth.getTransactionByBlockNumberAndIndex("latest", 0).pipe( Effect.map((transaction) => transaction?.hash),);- JSON-RPC:
eth_getTransactionByBlockNumberAndIndex - Parameters:
block(BlockId.NumberOrTag), thenindex(number), counted from0. - Returns:
Transaction.Transaction, ornullwhen the node does not have the block or the block has no transaction at that position.
getTransactionByBlockHashAndIndex
Section titled “getTransactionByBlockHashAndIndex”Returns the transaction at a position in a block, by the hash of the block.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const first = Eth.getTransactionByBlockHashAndIndex( "0xe5178f52e018186949d9fe9168c6011820f9c6bd449a93dbb07c09dfc0af3dfa", 0,);- JSON-RPC:
eth_getTransactionByBlockHashAndIndex - Parameters:
blockHash(Hash), thenindex(number), counted from0. - Returns:
Transaction.Transaction, ornullwhen no block has the hash or the block has no transaction at that position.
getTransactionBySenderAndNonce
Section titled “getTransactionBySenderAndNonce”Returns the transaction an account sent with a given nonce.
import { Effect } from "effect";import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const firstSent = Effect.gen(function* () { const transaction = yield* Eth.getTransactionBySenderAndNonce(ADDRESS, 0); return transaction?.hash;});// "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3"- JSON-RPC:
eth_getTransactionBySenderAndNonce - Parameters:
address(Address.Address), thennonce(number). - Returns:
Transaction.Transaction, ornullwhen the account sent nothing with that nonce. anvil finds a transaction that is still pending too. - Not served by every client.
getRawTransactionByHash
Section titled “getRawTransactionByHash”Returns a transaction in its signed, encoded form: the bytes that
Eth.sendRawTransaction takes.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const raw = Eth.getRawTransactionByHash( "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3",);// "0x02f8…": the first byte, 0x02, is the type of an EIP-1559 transaction- JSON-RPC:
eth_getRawTransactionByHash - Parameters:
hash(Hash). - Returns:
Hex, ornullwhen the node does not know the hash. A pending transaction has a raw form too.
getRawTransactionByBlockNumberAndIndex
Section titled “getRawTransactionByBlockNumberAndIndex”Returns the signed, encoded form of the transaction at a position in a block, by the number or tag of the block.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const raw = Eth.getRawTransactionByBlockNumberAndIndex("latest", 0);- JSON-RPC:
eth_getRawTransactionByBlockNumberAndIndex - Parameters:
block(BlockId.NumberOrTag), thenindex(number), counted from0. - Returns:
Hex, ornullwhen the block has no transaction at that position.
getRawTransactionByBlockHashAndIndex
Section titled “getRawTransactionByBlockHashAndIndex”Returns the signed, encoded form of the transaction at a position in a block, by the hash of the block.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const raw = Eth.getRawTransactionByBlockHashAndIndex( "0xe5178f52e018186949d9fe9168c6011820f9c6bd449a93dbb07c09dfc0af3dfa", 0,);- JSON-RPC:
eth_getRawTransactionByBlockHashAndIndex - Parameters:
blockHash(Hash), thenindex(number), counted from0. - Returns:
Hex, ornullwhen no block has the hash or the block has no transaction at that position.
pendingTransactions
Section titled “pendingTransactions”Returns the transactions waiting in the node’s pending pool.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const waiting = Eth.pendingTransactions().pipe( Effect.map((transactions) => transactions.map(({ from, nonce, hash }) => ({ from, nonce, hash })), ),);- JSON-RPC:
eth_pendingTransactions - Parameters: none.
- Returns:
ReadonlyArray<Transaction.Transaction>, empty when the pool is. Each one hasblockHash,blockNumberandtransactionIndexset tonull. - Not served by every client. To be told about each new one, use
Eth.subscribe.newPendingTransactions.
Behavior
Section titled “Behavior”- The same transaction, whatever the lookup. The three lookups that return a
Transactiongive the objectEth.getTransactionByHashgives. - Positions and nonces are
number. Anindexand anonceare notbigint. See values on the wire. - The raw form is not decoded. The hex is returned as the node sent it, and nothing public in ethect parses a signed transaction.
- A development node mines at once. On anvil the pool is empty unless automine is off:
see
Anvil.setAutomine.