How to get all transactions in a block
Fetch every transaction in any block with the GoldRush Block Transactions API: count them, page large blocks, build a block explorer view and flag wallets.
On this page
What the Block Transactions API returns
A block is an ordered batch of transactions. To list every transaction in one, with its sender, receiver, value, fee, status and decoded event logs, call the GoldRush Block Transactions API, part of the GoldRush Foundational API. It reads any block from genesis to the chain tip on every chain GoldRush indexes, in one response format, so the same code works on Ethereum, Base or Polygon.
There are two ways to name the block:
- By height, page by page: Block Transactions API by Page,
GET /v1/{chainName}/block/{blockHeight}/transactions_v3/page/{page}/.blockHeightalso acceptslatest. - By hash: Block Transactions API,
GET /v1/{chainName}/block_hash/{blockHash}/transactions_v3/.
Developers use block transactions for:
- block explorers and transaction feeds;
- per-block analytics: transaction counts, fees, value moved, active wallets;
- scanning each new block for watched wallets or large transfers.
What you need
- A GoldRush API key. Sign up to get one.
- The chain name, such as
eth-mainnet,base-mainnetormatic-mainnet. - A block height, or
latest.
Step 1: Fetch the transactions in one block
Send your key as a Bearer token and ask for page 0:
API=https://api.covalenthq.com/v1 curl "$API/eth-mainnet/block/1000000/transactions_v3/page/0/" \ -H "Authorization: Bearer $GOLDRUSH_API_KEY"Each item is one transaction. This is the first of the two in Ethereum block 1,000,000, abridged:
{ "block_signed_at": "2016-02-13T22:54:13.000Z", "block_height": 1000000, "block_hash": "0x8e38b4dbf6b11fcc3b9dee84fb7986e29ca0a02cecd8977c161ff7333329681e", "tx_hash": "0xea1093d492a1dcb1bef708f771a99a96ff05dcab81ca76c31940300177fcf49f", "tx_offset": 0, "successful": true, "from_address": "0x39fa8c5f2793459d6622857e7d9fbb4bd91766d3", "to_address": "0xc083e9947cf02b8ffc7d3090ae9aea72df98fd47", "value": "100000000000000000000", "value_quote": 516.9512436402438, "gas_metadata": { "contract_decimals": 18, "contract_ticker_symbol": "ETH" }, "gas_spent": 29244, "gas_price": 80525500000, "fees_paid": "2354887722000000", "explorers": [ { "label": "Etherscan", "url": "https://etherscan.io/tx/0xea1093d492a1dcb1bef708f771a99a96ff05dcab81ca76c31940300177fcf49f" } ], "log_events": [ { "sender_address": "0xc083e9947cf02b8ffc7d3090ae9aea72df98fd47", "decoded": { "name": "Deposit", "signature": "Deposit(indexed address dst, uint256 wad)", "params": [ { "name": "dst", "type": "address", "value": "0x39fa8c5f2793459d6622857e7d9fbb4bd91766d3" }, { "name": "wad", "type": "uint256", "value": "100000000000000000000" } ] } } ]}valueandfees_paidare integers in the chain's smallest unit (wei on Ethereum), sent as strings.gas_metadatagives the native token's decimals and symbol, so you can format them on any chain. The gwei guide explains the units.value_quoteis the native value in USD (or yourquote-currency) at the time of the block, not today's price.explorerslinks the transaction on the chain's own block explorer.log_eventsholds each event the transaction emitted, decoded where GoldRush knows the ABI, ornullwhen there were none.block_hashlets you drop transactions from a block that was later re-orged.
Unlike a node's JSON-RPC, which returns hex and needs a receipt call per transaction for logs and fees, one request returns decimals, fees and decoded logs for the whole page.
Step 2: Page through a large block
Busy blocks hold more transactions than one page. Step page from 0 and stop when links.next is null:
const API = "https://api.covalenthq.com/v1";const headers = { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}`,}; // Every transaction in one block, following the pages until links.next is nullasync function getBlockTransactions(chain, height, params = {}) { const txs = []; const query = new URLSearchParams(params); for (let page = 0; ; page++) { const url = `${API}/${chain}/block/${height}/transactions_v3/page/${page}/?${query}`; const res = await fetch(url, { headers }); if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`); const { data } = await res.json(); txs.push(...data.items); if (!data.links?.next) return txs; }} const txs = await getBlockTransactions("eth-mainnet", 1000000);console.log(txs.length, "transactions in block 1,000,000");Two query parameters change what comes back: quote-currency (such as USD, EUR, GBP or JPY) sets the currency of value_quote and gas_quote, and no-logs=true drops log_events, which makes the call cheaper when you only need the transactions themselves.
If you already have the block hash, for example from a re-org check, the by-hash endpoint returns the block's transactions in one call.
How many transactions are in a block?
Count the items across every page. Logs aren't needed for a count, so pass no-logs:
// Counting only: skip the decoded logsconst count = (await getBlockTransactions("eth-mainnet", 46147, { "no-logs": "true" })).length;console.log(count); // 1For the block itself (its hash, timestamp, miner, gas used and gas limit) call the Block API, GET /v1/{chainName}/block_v2/{blockHeight}/. It costs 1 per call and also returns transactions_link, a link to that block's transactions.
Build a block explorer view
A block explorer page is a block picker and a transactions table. Pick a chain and a height (or the latest block), fetch the block's transactions and render one row each. The amounts are formatted with the chain's own decimals and symbol from gas_metadata, and each hash links to the chain's explorer from explorers, so the same table works on every chain without a per-chain lookup.
// Raw integer string at `decimals` -> decimal string, without losing precisionfunction formatUnits(raw, decimals = 18) { const s = BigInt(raw) .toString() .padStart(decimals + 1, "0"); const whole = s.slice(0, -decimals); const frac = s.slice(-decimals).replace(/0+$/, ""); return frac ? `${whole}.${frac}` : whole;} async function getLatestHeight(chain) { const res = await fetch(`${API}/${chain}/block_v2/latest/`, { headers }); if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`); const { data } = await res.json(); return data.items[0].height;} const short = (a) => (a ? `${a.slice(0, 6)}…${a.slice(-4)}` : "contract creation"); function blockTable(txs) { const rows = txs.map((tx) => { const { contract_decimals: decimals, contract_ticker_symbol: symbol } = tx.gas_metadata; const link = tx.explorers?.[0]?.url; const hash = link ? `<a href="${link}">${short(tx.tx_hash)}</a>` : short(tx.tx_hash); return `<tr> <td>${hash}</td> <td>${short(tx.from_address)}</td> <td>${short(tx.to_address)}</td> <td>${formatUnits(tx.value, decimals)} ${symbol}</td> <td>${formatUnits(tx.fees_paid, decimals)} ${symbol}</td> <td>${tx.successful ? "Success" : "Failed"}</td></tr>`; }); return `<table><thead><tr><th>Tx hash</th><th>From</th><th>To</th><th>Value</th><th>Fee</th><th>Status</th></tr></thead><tbody>${rows.join("")}</tbody></table>`;} // Render into <h2 id="title"> and <div id="txs">; omit height for the latest blockasync function showBlock(chain, height) { const h = height ?? (await getLatestHeight(chain)); const txs = await getBlockTransactions(chain, h, { "no-logs": "true" }); document.querySelector("#title").textContent = `${chain} block ${h}: ${txs.length} transactions`; document.querySelector("#txs").innerHTML = blockTable(txs);} showBlock("eth-mainnet", 46147);Keep the API key on a server: put getBlockTransactions behind your own backend route and have the page call that.
The block in the example is a piece of history. Ethereum's first blocks hold no transactions, and block 46147, signed on 7 August 2015, holds what is widely cited as its first transaction. The table shows one row: 0x5c50…2060 from 0xa1e4…63b4, a value of 31337 wei (0.000000000000031337 ETH) and a fee of 1.05 ETH, paid at a gas price of 50,000 gwei.
To show the event names in a column, as Etherscan's logs tab does, fetch without no-logs and list tx.log_events?.map((e) => e.decoded?.name).
Monitor new blocks and flag wallets or large transfers
The same call is the core of a simple alerting job for blockchain transaction monitoring: poll for the latest block at about the chain's block time, fetch each new block's transactions, and flag the ones that match your rules.
Two rules cover most watchlists:
- A watched address: it's the sender or receiver, or it appears in a decoded event. An ERC-20 transfer's
to_addressis the token contract, not the recipient, so the recipient only shows up in theTransferevent's params. - A large native transfer:
value_quoteat or above a threshold.value_quotecovers the chain's native token only; token amounts are in the events.
const WATCHED = new Set(["0x39fa8c5f2793459d6622857e7d9fbb4bd91766d3"].map((a) => a.toLowerCase()));const MIN_VALUE_USD = 100_000; function reasonsToFlag(tx) { const reasons = []; if (WATCHED.has(tx.from_address) || WATCHED.has(tx.to_address)) reasons.push("watched address"); const inLogs = (tx.log_events ?? []).some((log) => (log.decoded?.params ?? []).some((p) => typeof p.value === "string" && WATCHED.has(p.value.toLowerCase())) ); if (inLogs && !reasons.length) reasons.push("watched address in an event"); if ((tx.value_quote ?? 0) >= MIN_VALUE_USD) reasons.push("large native transfer"); return reasons;} const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); // Scan every block from now on; onFlag sends the alert (email, Slack, a queue)async function watchChain(chain, onFlag, pollMs = 12_000) { let next = await getLatestHeight(chain); for (;;) { const tip = await getLatestHeight(chain); for (; next <= tip; next++) { for (const tx of await getBlockTransactions(chain, next)) { const reasons = reasonsToFlag(tx); if (reasons.length) await onFlag(tx, reasons); } } await sleep(pollMs); }} watchChain("eth-mainnet", async (tx, reasons) => { console.log(reasons.join(", "), tx.explorers?.[0]?.url ?? tx.tx_hash);});To match on an event type instead of an address, test log.decoded?.name, for example "Swap" or "Transfer". Store next somewhere durable so a restart picks up where it stopped, and back off on a 429 as error handling describes.
Polling suits a handful of rules on one chain. For alerts pushed to you as wallets act, the GoldRush Streaming API has a wallet activity stream; its overview lists the chains it serves today.
What it costs
Both block transactions endpoints cost 0.1 per item, so a block of 200 transactions costs 20 credits with logs. no-logs lowers the per-item cost, and a request that returns no transactions has a small base cost; the API reference lists both. The Block API costs 1 per call. The pricing calculator estimates a month of calls, for example one block per poll on one chain.
Frequently asked questions
How many transactions are in a block?
It varies by chain and by block. Fetch the block with the Block Transactions API by Page, follow links.next until it is null, and count the items. Pass no-logs=true when you only need the count.
How do I get all transactions in a block with an API?
Call GET /v1/{chainName}/block/{blockHeight}/transactions_v3/page/0/ with your GoldRush key, then keep requesting the next page while links.next is set. Each item has the hash, sender, receiver, value, fee, status and decoded event logs. Use latest as the height for the newest block.
How do I build a block explorer?
Start with two calls: the Block API for the latest height and block details, and the Block Transactions API for the transactions in a block. Render the transactions as a table of hash, from, to, value, fee and status, format amounts with gas_metadata decimals, and link each hash with explorers. The same code works on every chain GoldRush indexes.
Can I get transactions from old blocks?
Yes. Any block from genesis is available. Ethereum block 46147, from August 2015, returns what is widely cited as the chain's first transaction: 31337 wei, with a fee of 1.05 ETH.
How do I monitor a blockchain for a wallet's transactions?
Poll the latest block at about the chain's block time, fetch each new block's transactions and keep those where the address is the sender, the receiver or a decoded event parameter. For pushed updates instead of polling, see the GoldRush Streaming API's wallet activity stream, on the chains its overview lists.
Should I fetch a block by height or by hash?
By height is simplest and accepts latest. By hash pins one exact block, which matters near the chain tip, where a block at a given height can be replaced in a re-org. Every item carries block_hash, so you can check which block it came from either way.
Next steps
- Block Transactions API by Page: every parameter and response field.
- Block Transactions API: the same transactions by block hash.
- Block API: block height, hash, time and gas.
- Transaction API: one transaction by hash, with its decoded logs.
- GoldRush Foundational API: the chains, endpoints and pricing.