APIs used:
  • Get all transactions in a block (v3)  

Perhaps you’re a frontend developer building a block visualizer, or a data scientist doing block-level analysis across layer 1 networks. Or maybe you are a blockchain engineer who needs to spin up a block explorer quickly. Whatever your use case may be, you realize that you need to get all transactions data within a block - not just the transaction hashes, but detailed information such as the value of each transaction, its fees, log events, etc. Now, how can that be done?

Covalent has an all-new endpoint that allows you to get granular data on every single transaction within a block across the 200+ chains we support.

Get all transactions in a block (v3)

GET/v1/{chainName}/block/{blockHeight}/transactions_v3/

Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.

With the data, you can answer questions like:

  • How many unique wallets are active in every block?

  • How many transactions are OpenSea transactions in the latest block?

  • What are the total gas fees spent in every block?

Quick Start

Assuming you already have an API key, you can simply paste this into the browser to see the latest transactions on Ethereum mainnet:

https://api.covalenthq.com/v1/eth-mainnet/block/latest/transactions_v3/?key=ckey_sample

Remember to replace ckey_sample with your own API key.

Get Transactions in a Block API Response

*This is a sample response showing only the first 2 transactions:

json
{
  "data": {
    "updated_at": "2023-01-19T04:15:43.477125413Z",
    "items": [
      {
        "block_signed_at": "2023-01-17T20:49:35Z",
        "block_height": 16429017,
        "tx_hash": "0x38f98a90716a9d3d5b43908c8dfd27f5db07cd81e4dc2cc234254600288da5f6",
        "tx_offset": 0,
        "successful": true,
        "from_address": "0x953b239b656f611b65f86e0e6a99e6b500f6bc9a",
        "from_address_label": null,
        "to_address": "0x0000a42df58060230d7f1aefe47da338078244e8",
        "to_address_label": null,
        "value": "5968955874",
        "value_quote": 0.000009407811104688234,
        "gas_offered": 2535898,
        "gas_spent": 1267949,
        "gas_price": 25309574640,
        "fees_paid": "32091249855213360",
        "gas_quote": 50.57977025199248,
        "gas_quote_rate": 1576.1234130859375,
        "log_events": []
      },
      {
        "block_signed_at": "2023-01-17T20:49:35Z",
        "block_height": 16429017,
        "tx_hash": "0x3f63c7b2466aa73b9ed08d1831585ed69897326de996d45b34f91dd0952b8491",
        "tx_offset": 1,
        "successful": true,
        "from_address": "0xf04c905f22c7e34d9b58303eb614c3acd070175f",
        "from_address_label": null,
        "to_address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
        "to_address_label": null,
        "value": "19522735180045662",
        "value_quote": 30.77024000474648,
        "gas_offered": 2000000,
        "gas_spent": 155308,
        "gas_price": 35509574640,
        "fees_paid": "5514921018189120",
        "gas_quote": 8.69219613808761,
        "gas_quote_rate": 1576.1234130859375,
        "log_events": []
      }
    ]
  }
}

In the sample response above, each item in the items array represents one transaction within the block. Only two are displayed due to space constraints, but if you were to try it yourself in the browser, you will notice that the response will contain all the transactions in the latest block.

Covalent Transaction Data vs. RPC

In contrast to JSON-RPC, where most of the values returned are in hexadecimal, Covalent’s responses are converted to decimals for simplicity. For instance, the fields block_signed_at, value, or gas_price are all in decimals. Furthermore, the Covalent response contains a very useful value_quote field, which reflects the USD value of the value field at the time of the transaction.

"value_quote": 30.77024000474648

This field allows you to quickly display the real fiat value of a transaction at the point of the transaction, instead of a variable one, enabling you to build a button like this:

In the case of the value field of the Covalent response, it is important to note that the large number you see is denominated in wei.

"value": "19522735180045662"

To find the corresponding value in the standard unit of ETH, you can take value/(10^18). In our case, that is equal to:

19522735180045662/(10^18) = 0.0195227

Decoded Event Logs

One prominent feature of the endpoint is that it returns the decoded event logs of a transaction.

json
...
log_events: [{
  "block_signed_at": "2023-01-19T22:44:47Z",
  "block_height": 16443913,
  "tx_offset": 0,
  "log_offset": 0,
  "tx_hash": "0x1121ecf9300846df8d6952ba99ad3012b209d4f54289b4d0e2b95ee5e7ed3f92",
  "raw_log_topics": [
    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
    "0x00000000000000000000000094484f0353c37feb11da98985bd965cff7b68830",
    "0x000000000000000000000000b2f708f09beb7e5aa2052380188cfeaab91449c1"
  ],
  "sender_contract_decimals": 18,
  "sender_name": "Wrapped Ether",
  "sender_contract_ticker_symbol": "WETH",
  "sender_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  "sender_address_label": null,
  "sender_logo_url": "<https://logos.covalenthq.com/tokens/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png>",
  "raw_log_data": "0x000000000000000000000000000000000000000000000000007265bab9c48000",
  "decoded": {
    "name": "Transfer",
    "signature": "Transfer(indexed address from, indexed address to, uint256 value)",
    "params": [
      {
        "name": "from",
        "type": "address",
        "indexed": true,
        "decoded": true,
        "value": "0x94484f0353c37feb11da98985bd965cff7b68830"
      },
      {
        "name": "to",
        "type": "address",
        "indexed": true,
        "decoded": true,
        "value": "0xb2f708f09beb7e5aa2052380188cfeaab91449c1"
      },
      {
        "name": "value",
        "type": "uint256",
        "indexed": false,
        "decoded": true,
        "value": "32200000000000000"
      }
    ]
  }
},
...

This is taken from the first transaction response in our API call earlier.

There’s a lot going on in the response. If you’re unfamiliar with event logs, topic hashes, or indexed topics, do check out this article.

With event logs, you will be able to have even deeper insights into what goes on under the hood of transactions. Due to the principle of composability of blockchains and the unstructured nature of data, there is no limit to the number of event logs a transaction can emit. Some transactions, such as this one, emit upwards of hundreds of events. Most fall between 1 to 5.

In our example above, the event log is decoded:

json
...
"decoded": {
    "name": "Transfer",
    ...
}

Having human-readable decoded event names allows us to identify this event as a "Transfer" event. This is a powerful feature of the endpoint.

Common Use Cases for Transactions in a Block

So what can you build? There are a few categories of use cases where the endpoint is really helpful.

  • Block explorer: The most obvious one is when you need any kind of block-level data. For instance, if you want to build a block explorer, or a transaction flow visualizer. Simply call the endpoint every time a block is produced, and get all updated transactions on your app in near real-time.

  • Aggregating transaction data: The second category of use case performs some kind of aggregation on the data. Suppose you are a data analyst and you want to find out what is the total ETH value being exchanged in each block. You can simply make a call to the endpoint, and sum up the value field to get the data that you need. Because the responses contain decoded log events, you can essentially filter and aggregate based on whatever condition you want to analyze: the number of swaps, the total value of NFT mints, and so on.

Of course, there are way more use cases than the ones highlighted above. Theendpoint represents all transactions that a chain produces at any given point, making it a useful tool to add to any developer's arsenal.