0

I'm having some concerns while developing smart contract. As I see that, Ethereum blockchain can be known as a distributed database, where transactions are stored as hashes in a block. A smart contract is the back-end of the DApp. In my scenario, I store data "this is my input" in a block by sending a transaction from accountA to accountB. As I see(Or I missed something)there is no option for me to get that data from the smart contract. Is it because the code for that function not supported by the solidity language, or it is the issue from the EVM, that has no opcodes to retrieve and decode the transaction. I read multiple documents but no one mentioned about how smart contract can get data that is not stored in its own storage.

Regards,

4
  • I lost you at I store data "this is my input" in a block by sending a transaction from accountA to accountB. As I see, there is no option for me to get that data from the smart contract.... Where did that smart contract "all of the sudden" came from??? Please consider adding a short coding example in order to clarify your question. Nov 30 '20 at 10:50
  • I'm sorry for confusing you. My scenario is like this: I create a transction from Java application: EthSendTransaction sendTrans = txManager.sendTransaction(DefaultGasProvider.GAS_PRICE , DefaultGasProvider.GAS_LIMIT, accountB_Addr, txData, BigInteger.ZERO); the "txData" is hash of = "This is my data" This transaction is mined inside a block. From a smart contract which has different address, I want to get this transaction and decoded it to the original str
    – Eth.Cat
    Nov 30 '20 at 10:55
  • You can actually store such information ('this is my input) in a smart contract variable or array, and read the content afterwards. This is not linked with transactions, which you will use to call the smart contract function to store o read variables. On the other hand, if you are talking about reading external sources from a smart contract, then this is all about Oracles, which is a different (and a bit more complex) topic. I think you just need to call another function in the smart contract to read what you previously stored.. Nov 30 '20 at 10:56
  • And yes I know it is not possible to get the above data from a smart contract. But I want to have a theoretical explanation or documentation that explain why it is not possible to do so. It is because the EVM itself just not provide the opcodes for doing it or any other reason.
    – Eth.Cat
    Nov 30 '20 at 11:00
0

I'm not quite sure if I understood correctly your problem but let's see.

Smart contracts have access to two types of data:

  1. Data sent to them and

  2. Data they access by calling another smart contract

So a smart contract can't "read" data from a client in that sense. Contracts also can't read data sent between two accounts directly - although such transactions typically don't even contain data.

2
  • thank you @Lauri Peltonen for your answer, but could you please provide me some documentation that explain why it is not possible to do so?
    – Eth.Cat
    Nov 30 '20 at 11:01
  • A valid question. Unfortunately I really don't know what documentation to provide you with - this is such a fundamental thing. You could at least check the Ethereum whitepaper ethereum.org/en/whitepaper and after that the yellow paper Nov 30 '20 at 11:14
0

A smart contract functionality is limited by EVM opcodes available. If there is no opcode for an action it won't be able to directly perform that action.

In this particular case there is no opcode to access other transactions inputs. A contract can only access its own inputs. The opcodes that allow a contract to read the transaction input are: CALLDATALOAD, CALLDATASIZE and CALLDATACOPY.

For many task it is possible to use an oracle to query for additional input.

1
  • thank you for your answer.
    – Eth.Cat
    Nov 30 '20 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.