Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ethereum/Solidity - Query Transactions

Does solidity have the ability to query transactions it puts on the blockchain, based on data in the transaction? By query I mean within solidity code running inside a smart contract (not web3.js running outside a smart contract)

So yesterday my contract executed a down payment transaction, today I want to query any/all blockchain transactions for this smart contract with a transaction type of "dp" or down payment? I want this query code to run or execute inside my smart contract.

I am not after a tx hash, I want the entire tx data for a specific transaction or transactions based on parameters, like transaction type, from address or date/time, etc.

NOTE: I want to query these transactions by executing solidity code inside my smart contract. I DO NOT WANT to use web3.js - please, please, please don't provide an answer with web3.js --- the querying has to be done inside the smart contract in solidity code. I appreciate your help - but if you answer is web3.js then you're really not helping

PLEASE - if anyone has seen examples of querying blockchain transaction in solidity code, please post a link or mention it. It seems very odd that you can post transactions to the BC, but there's not a get or retrieve or query function built into solidity. That seems, well to be honest, so basic.

I found out that while solidity can do event logging, such that all tx's are logged into a special area in the BC -- SADLY -- solidity code executing within a smart contract CAN NOT read these logs https://www.bitdegree.org/learn/solidity-events/

I just don't get it......why, why, why would you have a language that creates transactions but can't read them or query them. It just doesn't make sense to me.

I greatly appreciate answers from those knowledgeable in solidity!! Thank You Vmusic

like image 889
Alex Kerezy Avatar asked Aug 02 '18 01:08

Alex Kerezy


1 Answers

This is not possible. Contracts cannot query arbitrary state within the blockchain history.

Your only options are:

  1. Maintain a record of whatever state changes within the contract, and check those states to determine if a previous transaction has take place/current transaction is valid
  2. Use web3 to retrieve the details off chain and pass it as arguments to your contract
  3. Use a service like oraclize to query external data from your smart contract. This will also eventually end up making the query off chain, but you can initiate it within a smart contract and read the results back.
like image 52
Raghav Sood Avatar answered Oct 04 '22 03:10

Raghav Sood