bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex",
"params": ["latest", "0x0"],
"id": "getblock.io"
}'
javascriptconst axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getTransactionByBlockNumberAndIndex',
params: ['latest', '0x0'],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const tx = response.data.result;
if (tx) {
console.log('From:', tx.from);
console.log('To:', tx.to);
console.log('Hash:', tx.hash);
}
pythonimport requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_getTransactionByBlockNumberAndIndex',
'params': ['latest', '0x0'],
'id': 'getblock.io'
}
)
result = response.json()
tx = result['result']
if tx:
print(f'From: {tx["from"]}')
print(f'To: {tx["to"]}')
print(f'Hash: {tx["hash"]}')
rustuse reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&json!({
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex",
"params": ["latest", "0x0"],
"id": "getblock.io"
}))
.send()
.await?
.json::<Value>()
.await?;
println!("Transaction: {}", serde_json::to_string_pretty(&response["result"])?);
Ok(())
}
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
async function getTxByBlockNumberAndIndex(blockNumber, index) {
// Get the block with full transactions
const block = await provider.getBlock(blockNumber, true);
if (block && block.transactions[index]) {
const tx = block.transactions[index];
console.log('Transaction Hash:', tx.hash);
console.log('From:', tx.from);
console.log('To:', tx.to);
console.log('Value:', ethers.formatEther(tx.value), 'ETH');
return tx;
} else {
console.log('Transaction not found');
return null;
}
}
// Get first transaction of latest block
getTxByBlockNumberAndIndex('latest', 0);
// Get specific block and index
getTxByBlockNumberAndIndex(19800000, 0);
javascriptimport { createPublicClient, http, formatEther } from 'viem';
import { base } from 'viem/chains';
const client = createPublicClient({
chain: base,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
async function getTxByBlockNumberAndIndex(blockNumber, index) {
const tx = await client.getTransaction({
blockNumber: BigInt(blockNumber),
index: index
});
if (tx) {
console.log('Transaction Hash:', tx.hash);
console.log('From:', tx.from);
console.log('To:', tx.to);
console.log('Value:', formatEther(tx.value), 'ETH');
}
return tx;
}
getTxByBlockNumberAndIndex(19800000, 0);