> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.chainstack.com/feedback

```json
{
  "path": "/reference/ethereum-gettransactionbyblockhashandindex",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# eth_getTransactionByBlockHashAndIndex | Ethereum

Ethereum API method that retrieves information about a specific transaction based on the block hash and the transaction index within the block. This information can be used to track transactions, debug issues, analyze data, and build decentralized applications on the Ethereum blockchain.

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `hash` — the hash of the block
* `quantity` — the integer identifying the transaction index position within the block, encoded as hexadecimal

## Response

* `object` — a transaction response object, or `null` if no transaction is found:
  * `blockHash` — the block hash. Identifies the block in which the transaction was included. This field is `null` for transactions that have not yet been included in a block.
  * `blockNumber` — the number of the block in which the transaction was included. This field is `null` for transactions that have not yet been included in a block.
  * `from` — the address of the sender who initiated the transaction.
  * `gas` — the units of gas included in the transaction by the sender.
  * `gasPrice` — the price of gas in Wei included in the transaction by the sender.
  * `maxFeePerGas` — the maximum amount the sender of the transaction is willing to pay per unit of gas for the transaction to be executed.
  * `maxPriorityFeePerGas` — the maximum priority fee the sender of the transaction is willing to pay per unit of gas.
  * `hash` — the hash that uniquely identifies the transaction.
  * `input` — the optional input data sent with the transaction, usually used to interact with smart contracts.
  * `nonce` — a counter identifying the transaction's number sent by the sender wallet. It essentially identifies how many transactions an account has made. Used to ensure each transaction is executed only once.
  * `to` — the address of the recipient of the transaction if it was a transaction to an address. For contract creation transactions, this field is `null`.
  * `transactionIndex` — the index of the transaction within the block. It is `null` for transactions that have not yet been included in a block.
  * `value` — the value of the native token transferred along with the transaction, in Wei.
  * `type` — the [type](https://ethereum.org/en/developers/docs/transactions/#types-of-transactions) of the transaction. `0` indicates a regular transfer; `2` indicates a contract creation or smart contract function call.
  * `accessList` — a list of [authorized addresses and storage keys](https://eips.ethereum.org/EIPS/eip-2930#:~:text=The%20accessList%20specifies%20a%20list,of%20accessing%20outside%20the%20list.) the transaction plans to interact with.
  * `v` — the recovery parameter in the [Ethereum Signature Algorithm](https://ethereum.org/en/glossary/#ecdsa) (ECDSA).
  * `r` — the first component of the signature in the [Ethereum Signature Algorithm](https://ethereum.org/en/glossary/#ecdsa) (ECDSA).
  * `s` — the second component of the signature in the [Ethereum Signature Algorithm](https://ethereum.org/en/glossary/#ecdsa) (ECDSA).

## `eth_getTransactionByBlockHashAndIndex` code examples

<Note>
  Learn more about the `ChainstackProvider` in `ethers.js`: [ethers ChainstackProvider Documentation](/reference/ethersjs-chainstackprovider).
</Note>

<CodeGroup>
  ```javascript ethers.js theme={"system"}
  const ethers = require("ethers");

  // Create a ChainstackProvider instance for Ethereum mainnet
  const chainstack = new ethers.ChainstackProvider("mainnet");

  const getTransaction = async (blockHash, index) => {
    const transaction = await chainstack.send(
      "eth_getTransactionByBlockHashAndIndex",
      [blockHash, index]
    );
    console.log(transaction);
  };

  getTransaction(
    "0x6f5542b045b72ed449480bf363726e211635fe30702dafcd1907b93bd627b2e4",
    "0x3D"
  );
  ```

  ```javascript web3.js theme={"system"}
  const { Web3 } = require("web3");
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const web3 = new Web3(NODE_URL);

  async function getTransaction() {
    const transaction = await web3.eth.getTransactionFromBlock("0x6f5542b045b72ed449480bf363726e211635fe30702dafcd1907b93bd627b2e4", 22);
    console.log(transaction);
  }

  getTransaction();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "CHAINSTACK_NODE_URL" 

  web3 = Web3(Web3.HTTPProvider(node_url)) 
  print(web3.eth.get_transaction_by_block("0x6f5542b045b72ed449480bf363726e211635fe30702dafcd1907b93bd627b2e4", 22))
  ```
</CodeGroup>

## Use case

The `eth_getTransactionByBlockHashAndIndex` can be used to retrieve transaction details from a block. In the following example the `getSendersInBlock` checks how many transactions exist in a block, then receives the sender of each (`from` field) and displays it.

<Note>
  Note that there are simpler ways to get this information, and this is only a practical example of how to use `eth_getTransactionByBlockHashAndIndex`, if the number of transactions in the block is already known, the first step can be skipped.
</Note>

```javascript index.js theme={"system"}
const { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

async function getSendersInBlock(blockHash) {
  const block = await web3.eth.getBlock(blockHash);
  const transactions = block.transactions;
  
  console.log(`Block ${blockHash} contains ${transactions.length} transactions`);

  for (let i = 0; i < transactions.length; i++) {
    const transaction = await web3.eth.getTransactionFromBlock(blockHash, i);
    console.log(`Sender of transaction at index ${i}:`, transaction.from);
  }
}

getSendersInBlock("0x6f5542b045b72ed449480bf363726e211635fe30702dafcd1907b93bd627b2e4");
```

The number of transactions in the block is determined using `transactions.length` and the total number of transactions logged to the console.

A `for` loop is then used to retrieve information about each transaction in the block. For each iteration of the loop, the code calls the `web3.eth.getTransactionFromBlock` method to retrieve information about the transaction at the current index. The `from` property of the returned transaction object is logged to the console to show the sender of the transaction.


## OpenAPI

````yaml /openapi/ethereum_node_api/transaction_info/eth_getTransactionByBlockHashAndIndex.json POST /0a9d79d93fb2f4a4b1e04695da2b77a7
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-422-757-666.p2pify.com
security: []
paths:
  /0a9d79d93fb2f4a4b1e04695da2b77a7:
    post:
      tags:
        - upload
      summary: eth_getBalance
      operationId: getBalance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: eth_getBalance
                params:
                  type: array
                  items:
                    anyOf:
                      - type: string
                        title: Address
                        description: The address identifier.
                      - type: string
                        title: Block identifier
                        description: The block identifier.
                  default:
                    - '0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990'
                    - pending
      responses:
        '200':
          description: The account balance.
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````