eth_getTransactionByBlockNumberAndIndex
Overview
The 'eth_getTransactionByBlockNumberAndIndex' method returns information about a transaction by block number and transaction index position.
Request
- shell
- csharp
- php
- python
- javascript
- go
- ruby
- java
curl --request POST \
--url https://ethereum-mainnet-geth-archive.node.coinapi.io \
--header 'accept: application/json' \
--header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex"
}'
using RestSharp; {
var options = new RestClientOptions("https://ethereum-mainnet-geth-archive.node.coinapi.io");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json","X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY");
request.AddJsonBody("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionByBlockNumberAndIndex\"}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content); }
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://ethereum-mainnet-geth-archive.node.coinapi.io",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getTransactionByBlockNumberAndIndex'
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"content-type: application/json",
"X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
import requests
url = "https://ethereum-mainnet-geth-archive.node.coinapi.io"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex"
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-CoinAPI-Key" : "73034021-THIS-IS-SAMPLE-KEY"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
const options = {
method: 'POST',
headers: {accept: 'application/json', 'content-type': 'application/json', 'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'},
body: JSON.stringify({id: 1, jsonrpc: '2.0', method: 'eth_getTransactionByBlockNumberAndIndex'})
};
fetch('https://ethereum-mainnet-geth-archive.node.coinapi.io', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://ethereum-mainnet-geth-archive.node.coinapi.io"
payload := strings.NewReader("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionByBlockNumberAndIndex\"}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("accept", "application/json")
req.Header.Add("content-type", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
require 'uri'
require 'net/http'
url = URI("https://ethereum-mainnet-geth-archive.node.coinapi.io")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request["X-CoinAPI-Key"] = '73034021-THIS-IS-SAMPLE-KEY'
request.body = "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionByBlockNumberAndIndex\"}"
response = http.request(request)
puts response.read_body
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionByBlockNumberAndIndex\"}");
Request request = new Request.Builder()
.url("https://ethereum-mainnet-geth-archive.node.coinapi.io")
.post(body)
.addHeader("accept", "application/json")
.addHeader("content-type", "application/json")
.addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
.build();
Response response = client.newCall(request).execute();
Request Parameters
- block parameter: [ Required ] A hexadecimal block number, or the string latest, earliest or pending.
- transaction index position: [ Required ] A hexadecimal of the integer representing the position in the block.
Response
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "expected 'params' array of at least 2 arguments"
}
}
A transaction object, or null when no transaction was found. The transaction object will consist of the following keys and their values:
- blockHash: 32 bytes. A hash of the block including this transaction. 'null' when it's pending.
- accessList: [ optional ] A list of addresses and storage keys accessed by the transaction.
- blockNumber: The number of the block including this transaction. 'null' when it's pending.
- chainID: [ optional ] chain ID specifying the network. Returned only for EIP-1559 transactions.
- from: 20 bytes. The address of the sender.
- gas: Gas provided by the sender.
- gasPrice: Gas price provided by the sender in Wei.
- hash: 32 bytes. The hash of the transaction.
- input: The data sent along with the transaction.
- maxPriorityFeePerGas: [ optional ] Maximum fee, in Wei, the sender is willing to pay per gas above the base fee.
- maxFeePerGas: [ optional ] Maximum total fee (base fee + priority fee), in Wei, the sender is willing to pay per gas.
- nonce: The number of transactions made by the sender prior to this one.
- r: 32 bytes. The ECDSA signature 'r'.
- s: 32 bytes. The ECDSA signature 's'.
- to: 20 bytes. The address of the receiver. 'null' when it's a contract creation transaction.
- transactionIndex: The transaction's index position in the block, in hexadecimal. 'null' when it's pending.
- v: The ECDSA recovery ID.
- type: The transaction type.
- value: The value transferred in Wei.
Was this section helpful?