Is it possible to get contents of block using a transaction hash?

I tried using gettoblock function from moralis but it does not seem to accept transactions hash.

I want to use just chain name and transaction hash to get the contents of the block. Is it possible?

by a transaction hash you mean only a transaction from a specific block?
usually every eth transaction that is mined has a transaction hash, and multiple transactions are grouped together in order to form a block

for example:

in this u will see ā€œ0xb453852fad82c8d70440951a6a3c50534a49a59fd3b8287bbd10ee38fea7374cā€ is related to a block ā€œ19099895ā€.

I wanted to get the contents of the block ā€œ19099895ā€ using ā€œ0xb453852fad82c8d70440951a6a3c50534a49a59fd3b8287bbd10ee38fea7374cā€

  "hash": "0xb453852fad82c8d70440951a6a3c50534a49a59fd3b8287bbd10ee38fea7374c",
  "block_timestamp": "2021-09-14T13:54:12.000Z",
  "block_number": "19099895",
  "block_hash": "0x4e69ffd4fad673328d17ce0ea5258fcca063e5dd5f7ab85487dabb88ece6e287"

then you can make another call to get that block content

1 Like

Do we have a web3 API function to get it in the browser console? or is it only possible through API call?

You can use a cloud function for now, something like:

Moralis.Cloud.define("getTrasaction2", async (request) => {
  let a = '0xb453852fad82c8d70440951a6a3c50534a49a59fd3b8287bbd10ee38fea7374c'
  let url = "" + a + "?chain=polygon";;
  return Moralis.Cloud.httpRequest({
    "url": url,
    "headers": {
        'method': 'GET',
        'accept': 'application/json',
        'X-API-Key': 'API_KEY'}

Awesome. Thanks for the help.