# eth_getTransactionByBlockNumberAndIndex

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://sonic-mainnet.g.alchemy.com/v2/{apiKey}

Returns information about a transaction by block number and transaction index position.

Reference: https://www.alchemy.com/docs/chains/sonic/sonic-api-endpoints/eth-get-transaction-by-block-number-and-index

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Block | string or enum | Yes | The block number or tag ('latest', 'earliest', 'pending') containing the transaction. |
| Transaction index | string | Yes | The index position of the transaction in the block's transaction list, as a hexadecimal string. |

## Result

**Transaction information** (null or object): The transaction object containing various properties of the transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionByBlockNumberAndIndex",
  "params": [
    "0x1442e",
    "0x2"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "blockHash": "0x510efccf44a192e6e34bcb439a1947e24b86244280762cbb006858c237093fda",
    "blockNumber": "0x1442e",
    "chainId": "0x7e2",
    "from": "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
    "gas": "0x5208",
    "gasPrice": "0x3b9aca00",
    "hash": "0xa52be92809541220ee0aaaede6047d9a6c5d0cd96a517c854d944ee70a0ebb44",
    "input": "0x",
    "nonce": "0x1",
    "to": "0x627306090abab3a6e1400e9345bc60c78a8bef57",
    "transactionIndex": "0x2",
    "value": "0x4e1003b28d9280000",
    "v": "0x1c",
    "r": "0x84caf09aefbd5e539295acc67217563438a4efb224879b6855f56857fa2037d3",
    "s": "0x5e863be3829812c81439f0ae9d8ecb832b531d651fb234c848d1bf45e62be8b9"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://sonic-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_getTransactionByBlockNumberAndIndex",
  "params": [
    "0x1442e",
    "0x2"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_getTransactionByBlockNumberAndIndex',
    params: ['0x1442e', '0x2']
  })
};

fetch('https://sonic-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://sonic-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_getTransactionByBlockNumberAndIndex",
    "params": ["0x1442e", "0x2"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sonic-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getTransactionByBlockNumberAndIndex\",\n  \"params\": [\n    \"0x1442e\",\n    \"0x2\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://sonic-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getTransactionByBlockNumberAndIndex\",\n  \"params\": [\n    \"0x1442e\",\n    \"0x2\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://sonic-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getTransactionByBlockNumberAndIndex\",\n  \"params\": [\n    \"0x1442e\",\n    \"0x2\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: eth_getTransactionByBlockNumberAndIndex
description: Returns information about a transaction by block number and transaction index position.
params:
  - name: Block
    required: true
    description: The block number or tag ('latest', 'earliest', 'pending') containing the transaction.
    schema:
      title: Block number or tag
      oneOf:
        - title: Block number
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        - title: Block tag
          type: string
          enum:
            - earliest
            - finalized
            - safe
            - latest
            - pending
          description: '`earliest`: The lowest numbered block the client has available; `finalized`: The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination; `safe`: The most recent block that is safe from re-orgs under honest majority and certain synchronicity assumptions; `latest`: The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions; `pending`: A sample next block built by the client on top of `latest` and containing the set of transactions usually taken from local mempool. Before the merge transition is finalized, any call querying for `finalized` or `safe` block MUST be responded to with `-39001: Unknown block` error'
  - name: Transaction index
    required: true
    description: The index position of the transaction in the block's transaction list, as a hexadecimal string.
    schema:
      title: hex encoded unsigned integer
      type: string
      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
result:
  name: Transaction information
  description: The transaction object containing various properties of the transaction.
  schema:
    oneOf:
      - title: Not Found (null)
        type: 'null'
      - type: object
        title: Transaction information
        required:
          - blockHash
          - blockNumber
          - from
          - hash
          - transactionIndex
        unevaluatedProperties: false
        oneOf:
          - title: Signed 4844 Transaction
            type: object
            required:
              - accessList
              - blobVersionedHashes
              - chainId
              - gas
              - input
              - maxFeePerBlobGas
              - maxFeePerGas
              - maxPriorityFeePerGas
              - nonce
              - r
              - s
              - to
              - type
              - value
              - yParity
            properties:
              type:
                title: type
                type: string
                pattern: ^0x([0-9a-fA-F]?){1,2}$
              nonce:
                title: nonce
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              to:
                title: to address
                type: string
                pattern: ^0x[0-9a-fA-F]{40}$
              gas:
                title: gas limit
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              value:
                title: value
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              input:
                title: input data
                type: string
                pattern: ^0x[0-9a-f]*$
              maxPriorityFeePerGas:
                title: max priority fee per gas
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Maximum fee per gas the sender is willing to pay to miners in wei
              maxFeePerGas:
                title: max fee per gas
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The maximum total fee per gas the sender is willing to pay (includes the network / base fee and miner / priority fee) in wei
              maxFeePerBlobGas:
                title: max fee per blob gas
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The maximum total fee per gas the sender is willing to pay for blob gas in wei
              accessList:
                title: accessList
                description: EIP-2930 access list
                type: array
                items:
                  title: Access list entry
                  type: object
                  additionalProperties: false
                  properties:
                    address:
                      title: hex encoded address
                      type: string
                      pattern: ^0x[0-9a-fA-F]{40}$
                    storageKeys:
                      type: array
                      items:
                        title: 32 byte hex value
                        type: string
                        pattern: ^0x[0-9a-f]{64}$
              blobVersionedHashes:
                title: blobVersionedHashes
                description: List of versioned blob hashes associated with the transaction's EIP-4844 data blobs.
                type: array
                items:
                  title: 32 byte hex value
                  type: string
                  pattern: ^0x[0-9a-f]{64}$
              chainId:
                title: chainId
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Chain ID that this transaction is valid on.
              yParity:
                title: yParity
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
              r:
                title: r
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              s:
                title: s
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          - title: Signed 1559 Transaction
            type: object
            required:
              - accessList
              - chainId
              - gas
              - gasPrice
              - input
              - maxFeePerGas
              - maxPriorityFeePerGas
              - nonce
              - r
              - s
              - type
              - value
              - yParity
            properties:
              type:
                title: type
                type: string
                pattern: ^0x2$
              nonce:
                title: nonce
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              to:
                title: to address
                oneOf:
                  - title: Contract Creation (null)
                    type: 'null'
                  - title: Address
                    type: string
                    pattern: ^0x[0-9a-fA-F]{40}$
              gas:
                title: gas limit
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              value:
                title: value
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              input:
                title: input data
                type: string
                pattern: ^0x[0-9a-f]*$
              maxPriorityFeePerGas:
                title: max priority fee per gas
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Maximum fee per gas the sender is willing to pay to miners in wei
              maxFeePerGas:
                title: max fee per gas
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The maximum total fee per gas the sender is willing to pay (includes the network / base fee and miner / priority fee) in wei
              gasPrice:
                title: gas price
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The effective gas price paid by the sender in wei. For transactions not yet included in a block, this value should be set equal to the max fee per gas. This field is DEPRECATED, please transition to using effectiveGasPrice in the receipt object going forward.
              accessList:
                title: accessList
                description: EIP-2930 access list
                type: array
                items:
                  title: Access list entry
                  type: object
                  additionalProperties: false
                  properties:
                    address:
                      title: hex encoded address
                      type: string
                      pattern: ^0x[0-9a-fA-F]{40}$
                    storageKeys:
                      type: array
                      items:
                        title: 32 byte hex value
                        type: string
                        pattern: ^0x[0-9a-f]{64}$
              chainId:
                title: chainId
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Chain ID that this transaction is valid on.
              yParity:
                title: yParity
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
              v:
                title: v
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: For backwards compatibility, `v` is optionally provided as an alternative to `yParity`. This field is DEPRECATED and all use of it should migrate to `yParity`.
              r:
                title: r
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              s:
                title: s
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          - title: Signed 2930 Transaction
            type: object
            required:
              - accessList
              - chainId
              - gas
              - gasPrice
              - input
              - nonce
              - r
              - s
              - type
              - value
              - yParity
            properties:
              type:
                title: type
                type: string
                pattern: ^0x1$
              nonce:
                title: nonce
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              to:
                title: to address
                oneOf:
                  - title: Contract Creation (null)
                    type: 'null'
                  - title: Address
                    type: string
                    pattern: ^0x[0-9a-fA-F]{40}$
              gas:
                title: gas limit
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              value:
                title: value
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              input:
                title: input data
                type: string
                pattern: ^0x[0-9a-f]*$
              gasPrice:
                title: gas price
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The gas price willing to be paid by the sender in wei
              accessList:
                title: accessList
                description: EIP-2930 access list
                type: array
                items:
                  title: Access list entry
                  type: object
                  additionalProperties: false
                  properties:
                    address:
                      title: hex encoded address
                      type: string
                      pattern: ^0x[0-9a-fA-F]{40}$
                    storageKeys:
                      type: array
                      items:
                        title: 32 byte hex value
                        type: string
                        pattern: ^0x[0-9a-f]{64}$
              chainId:
                title: chainId
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Chain ID that this transaction is valid on.
              yParity:
                title: yParity
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
              v:
                title: v
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: For backwards compatibility, `v` is optionally provided as an alternative to `yParity`. This field is DEPRECATED and all use of it should migrate to `yParity`.
              r:
                title: r
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              s:
                title: s
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          - title: Signed Legacy Transaction
            type: object
            required:
              - gas
              - gasPrice
              - input
              - nonce
              - r
              - s
              - type
              - v
              - value
            properties:
              type:
                title: type
                type: string
                pattern: ^0x0$
              nonce:
                title: nonce
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              to:
                title: to address
                oneOf:
                  - title: Contract Creation (null)
                    type: 'null'
                  - title: Address
                    type: string
                    pattern: ^0x[0-9a-fA-F]{40}$
              gas:
                title: gas limit
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              value:
                title: value
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              input:
                title: input data
                type: string
                pattern: ^0x[0-9a-f]*$
              gasPrice:
                title: gas price
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: The gas price willing to be paid by the sender in wei
              chainId:
                title: chainId
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                description: Chain ID that this transaction is valid on.
              v:
                title: v
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              r:
                title: r
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
              s:
                title: s
                type: string
                pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        properties:
          blockHash:
            title: block hash
            type: string
            pattern: ^0x[0-9a-f]{64}$
          blockNumber:
            title: block number
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          from:
            title: from address
            type: string
            pattern: ^0x[0-9a-fA-F]{40}$
          hash:
            title: transaction hash
            type: string
            pattern: ^0x[0-9a-f]{64}$
          transactionIndex:
            title: transaction index
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
examples:
  - name: eth_getTransactionByBlockNumberAndIndex example
    params:
      - name: Block
        value: '0x1442e'
      - name: Transaction index
        value: '0x2'
    result:
      name: Transaction information
      value:
        blockHash: '0x510efccf44a192e6e34bcb439a1947e24b86244280762cbb006858c237093fda'
        blockNumber: '0x1442e'
        chainId: '0x7e2'
        from: '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73'
        gas: '0x5208'
        gasPrice: '0x3b9aca00'
        hash: '0xa52be92809541220ee0aaaede6047d9a6c5d0cd96a517c854d944ee70a0ebb44'
        input: 0x
        nonce: '0x1'
        to: '0x627306090abab3a6e1400e9345bc60c78a8bef57'
        transactionIndex: '0x2'
        value: '0x4e1003b28d9280000'
        v: '0x1c'
        r: '0x84caf09aefbd5e539295acc67217563438a4efb224879b6855f56857fa2037d3'
        s: '0x5e863be3829812c81439f0ae9d8ecb832b531d651fb234c848d1bf45e62be8b9'
```
