Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 561
i20gyawa Avatar asked Jun 21 '18 10:06

i20gyawa


People also ask

How do you get Ethereum transaction history?

It's easy to check your balance and transaction history on an Ethereum blockchain explorer like EthVM, Etherscan, or Ethplorer. These websites offer a full history of your activity. All you have to do is search your public Ethereum address, which is the 42 character string beginning with '0x'.

Can smart contracts store information?

Each smart contract deployed on the Neo blockchain owns a private storage where only the contract itself can read, write, modify, and delete data. Data in the storage is stored in the form of key-value pairs, where Key can be a string or a byte array (ByteArray) and Value can be any type.


1 Answers

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.

like image 158
Patrik Stas Avatar answered Sep 29 '22 21:09

Patrik Stas