Can we get transaction information recorded in the past block using Solidity in the Smart contract?
Asked Answered
D

1

10

I am studying blockchain with Ethereum, and I want to use past transaction data in the Smart contract using Solidity. If I use Web3.js module in the program written in javascript, I can get these data easily. But I can't get these data in the Smart contract using Solidity.

Reference of Solidity says that we can get current block number, blockhash, etc., by using "block.number" and "block.blockhash(uint blockNumber)" functions, but doesn't mention getting transaction data. (http://solidity.readthedocs.io/en/latest/units-and-global-variables.html#special-variables-and-functions)

enter image description here

please help me.

Dihedron answered 21/6, 2018 at 10:38 Comment(0)
K
13

The answer is simple. Unfortunately, you simply can’t access old transaction or block data onchain from Solidity. At most, you can access hashes of last 256 blocks (see blockhash in documentation )

Alternatively, as a workaround you could consider using Oraclize. Oraclize represents way to read offchain data onchain, so you could try to read transaction data from Etherscan web API. The way Oraclize works is that :

  1. You request to Oraclize smart contract what data you want to fetch from internet (some URL)
  2. Oraclize offchain servers then detect your on-chain request
  3. The look up the data you wanted (they'll make some http request to the URL you provided)
  4. Once they get response, they will send transaction to your contract (calling specific callback method) containing data you requested

With such approach however, you are relying that:

  1. EtherScan is up and running
  2. Oraclize is up un running.

If you only care about transaction data related to your smart contracts, another way would be to store that transaction data onchain. Maybe we could gave you some more suggestions if you tell us more about what specific problem are you solving.

Krieg answered 21/6, 2018 at 12:48 Comment(1)
Thank you very much for your prompt response. The means of using Oraclize is also very helpful. I am trying to develop a Smart contract to check the validity of new registration information from past transaction information, so I wanted to get transaction information on a Smart contract.Dihedron

© 2022 - 2024 — McMap. All rights reserved.