Premiers pas avec TheRPC
Ethereum/Core API/eth_getBlockReceipts

eth_getBlockReceipts

The eth_getBlockReceipts method returns all transaction receipts for a given block in a single call. This highly efficient method is significantly more performant than requesting individual receipts when you need data for multiple transactions in the same block, making it essential for blockchain indexers and analytics platforms.

Use Cases

  • Gas usage analysis and optimization
  • Transaction success/failure monitoring
  • Bulk transaction verification and processing
  • Log and event collection for indexing
  • Smart contract execution analysis and debugging
  • Block explorers and analytics platforms
  • Token transfer tracking and wallet updates
  • MEV (Maximal Extractable Value) analysis
  • Historical data aggregation
  • Batch event processing

Method Details

This method retrieves comprehensive transaction results including status, gas usage, logs, and events for all transactions in a specified block.

Paramètres:

Block number in hex format or tags: latest, earliest, pending, safe, finalized

Retours:

Array of transaction receipt objects, each containing:

Hash of the block containing this transaction

Block number in hexadecimal

Contract address created (if contract creation), otherwise null

Total gas used in the block up to and including this transaction

Price per gas actually paid, in wei (hexadecimal)

Address of the sender

Gas used by this specific transaction

Array of log objects generated by this transaction

Bloom filter for light clients to quickly retrieve related logs

1 (success) or 0 (failure)

Recipient address, or null for contract creation

Hash of the transaction

Transaction's index position in the block

Transaction type (0=legacy, 1=EIP2930, 2=EIP1559)

Response Example

{
	"jsonrpc": "2.0",
	"id": 1,
	"result": [
		{
			"blockHash": "0xb5876cd604e2234f800817ef7d744b55e3de0750679923ad3c8f3a3439f8095c",
			"blockNumber": "0x112bde2",
			"contractAddress": null,
			"cumulativeGasUsed": "0x21880",
			"effectiveGasPrice": "0x4940d0306",
			"from": "0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5",
			"gasUsed": "0x21880",
			"logs": [
				{
					"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
					"topics": [
						"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
						"0x00000000000000000000000095222290dd7278aa3ddd389cc1e1d165cc4bafe5",
						"0x000000000000000000000000333cb957ceaab5a7d2fd1f046f6a4481a52d7378"
					],
					"data": "0x000000000000000000000000000000000000000000000000000000000513cafb",
					"blockNumber": "0x112bde2",
					"transactionHash": "0x4e7c53bec74550e8c4bb3642c21708134f434994b122a3d6321ec718e743281d",
					"transactionIndex": "0x0",
					"blockHash": "0xb5876cd604e2234f800817ef7d744b55e3de0750679923ad3c8f3a3439f8095c",
					"logIndex": "0x0",
					"removed": false
				}
			],
			"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000020000000004000000000000000000000000000000000000000000000000000000000",
			"status": "0x1",
			"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
			"transactionHash": "0x4e7c53bec74550e8c4bb3642c21708134f434994b122a3d6321ec718e743281d",
			"transactionIndex": "0x0",
			"type": "0x2"
		},
		{
			"blockHash": "0xb5876cd604e2234f800817ef7d744b55e3de0750679923ad3c8f3a3439f8095c",
			"blockNumber": "0x112bde2",
			"contractAddress": null,
			"cumulativeGasUsed": "0x36f10",
			"effectiveGasPrice": "0x484c172f0",
			"from": "0xE4395bc3d18B93D5F22e75bA15704e7a5B0ca77f",
			"gasUsed": "0x15690",
			"logs": [
				{
					"address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
					"topics": [
						"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
						"0x000000000000000000000000e4395bc3d18b93d5f22e75ba15704e7a5b0ca77f",
						"0x00000000000000000000000001d1d3b37d6a73adcbe2d6c4a330b6b244f48d5a"
					],
					"data": "0x0000000000000000000000000000000000000000000000000000000016be7dbf",
					"blockNumber": "0x112bde2",
					"transactionHash": "0x87c3f77d7c2755c9a3b94985c17b97cedd96b2afb2a916e50e4357e2188a46ec",
					"transactionIndex": "0x1",
					"blockHash": "0xb5876cd604e2234f800817ef7d744b55e3de0750679923ad3c8f3a3439f8095c",
					"logIndex": "0x1",
					"removed": false
				}
			],
			"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000020000010000000000000000000000000000000000000000000000000000000000000",
			"status": "0x1",
			"to": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
			"transactionHash": "0x87c3f77d7c2755c9a3b94985c17b97cedd96b2afb2a916e50e4357e2188a46ec",
			"transactionIndex": "0x1",
			"type": "0x2"
		}
		// Additional receipts...
	]
}

Key Receipt Fields Explained

  • status: 0x1 for successful transactions, 0x0 for failed transactions
  • logs: Contains all emitted events (crucial for tracking token transfers and state changes)
  • gasUsed: Actual gas consumed by this transaction (important for cost analysis)
  • cumulativeGasUsed: Running total of gas used in the block up to this transaction
  • effectiveGasPrice: Actual price paid per gas unit (particularly important for EIP-1559 transactions)
  • contractAddress: Only populated for contract creation transactions
  • type: Indicates the transaction type (legacy, access list, or EIP-1559)

Common Event Signatures

The most common event signatures you'll encounter in logs:

  • ERC-20 Transfer: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
  • ERC-20 Approval: 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925
  • ERC-721 Transfer: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef (same as ERC-20)
  • ERC-1155 TransferSingle: 0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62
  • ERC-1155 TransferBatch: 0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb

Performance Advantages

This method offers significant performance benefits over individual receipt requests:

  1. Reduced Network Overhead: One request instead of many separate API calls
  2. Lower Latency: Minimized round-trip delays between client and node
  3. Decreased Resource Usage: Less processing required by both client and node
  4. Better Cache Utilization: Data can be returned from a single cache lookup
  5. Simplified Error Handling: Single request means simplified retry logic

Practical Example

// Example: Analyze token transfers in a block
async function analyzeTokenTransfers(blockNumber) {
	const receipts = await provider.send('eth_getBlockReceipts', [blockNumber]);

	// Common ERC-20 Transfer event signature
	const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';

	// Track all token transfers
	const tokenTransfers = {};

	receipts.forEach((receipt) => {
		// Skip failed transactions
		if (receipt.status !== '0x1') return;

		receipt.logs.forEach((log) => {
			if (log.topics[0] === transferTopic) {
				const token = log.address;
				const from = '0x' + log.topics[1].slice(26);
				const to = '0x' + log.topics[2].slice(26);
				const value = BigInt(log.data);

				if (!tokenTransfers[token]) {
					tokenTransfers[token] = [];
				}

				tokenTransfers[token].push({ from, to, value });
			}
		});
	});

	return tokenTransfers;
}

// Usage
const transfers = await analyzeTokenTransfers('0x112BDE2');
console.log(`Found transfers for ${Object.keys(transfers).length} different tokens`);

See also

Aidez-nous à nous améliorer !
Partagez cette page et aidez-nous à créer un produit encore meilleur pour vous.