How to get metadata using transaction hash using solidity or moralis?

I have transaction hash which I am able to see on etherscan but I want metadata of that transaction.
How can we do this.

You can use getTransaction API to get info on a transaction hash.

I have my code in solidity, then what can I do ?

Don’t think this is possible unless you use an oracle (which basically does something like query an API like Moralis for the transaction info). What use case would require looking up previous transactions only within a contract?