Skip to content

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.

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), then index (number), counted from 0.
  • Returns: Transaction.Transaction, or null when the node does not have the block or the block has no transaction at that position.

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), then index (number), counted from 0.
  • Returns: Transaction.Transaction, or null when no block has the hash or the block has no transaction at that position.

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), then nonce (number).
  • Returns: Transaction.Transaction, or null when the account sent nothing with that nonce. anvil finds a transaction that is still pending too.
  • Not served by every client.

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, or null when the node does not know the hash. A pending transaction has a raw form too.

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), then index (number), counted from 0.
  • Returns: Hex, or null when the block has no transaction at that position.

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), then index (number), counted from 0.
  • Returns: Hex, or null when no block has the hash or the block has no transaction at that position.

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 has blockHash, blockNumber and transactionIndex set to null.
  • Not served by every client. To be told about each new one, use Eth.subscribe.newPendingTransactions.
  • The same transaction, whatever the lookup. The three lookups that return a Transaction give the object Eth.getTransactionByHash gives.
  • Positions and nonces are number. An index and a nonce are not bigint. 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.