I'm having some concerns while developing a smart contract. As I see, the 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 how smart contracts can get data that is not stored in its own storage.


  • 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. Commented Nov 30, 2020 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
    Commented Nov 30, 2020 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.. Commented Nov 30, 2020 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
    Commented Nov 30, 2020 at 11:00
  • You can store data into a smart contract. It is very expensive, but ... If I understood you, I think you may create an array of non fungible records and store what you want there. To recover that record from another smart contract you will need at least a PK ( unique identifier) to find that record in the NFT array. You can store much more data into IPFS and link only the data hash to the contract array.
    – Magno C
    Commented Aug 15, 2023 at 16:54

3 Answers 3


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.

  • 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
    Commented Nov 30, 2020 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 Commented Nov 30, 2020 at 11:14

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.


Contracts solve this.

Each contract has a storage name space (key value store closer to the VM). You use a contract to lay out how you will use the storage and functions to set and get.

The blockchain provides a canonical transaction order and consensus, so if foo == "bar", it's because something made it so, a.k.a. a transaction.

You don't generally need to worry about the block that set it, because the current state is usually what you want. The underlying chain ensures it isn't misrepresenting, hasn't been tampered with, etc.

contract SetGet {

  string private foo;

  function setFoo(string calldata input) public {
     foo = input;

  function getFoo() public view returns (string memory) {
     return foo;

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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