0

I want to store a transaction on the ethereum blockchain with someText attached to it:

{
  from,
  to,
  value, 
  data: someText
}               

I later wish to retrieve that transaction and read the text that was attached to it.

But actually, I do not want to retrieve someText as it was originally stored in the transaction. I want to retrieve someText with someExtraText appended to it.

someExtraText should be generated and appended to someText dynamically, every time I request that transaction. Its value will not be fixed. It will be different every time.

The logic that generates someExtraText and appends it to someText before it is sent to me, should not reside on my server. It should also reside on the blockchain.

I know that there is a clear API on how to send transactions to the blockchain and how to retrieve them, using web3.js:

web3.eth.sendTransaction({
  from,
  to,
  value, 
  data: someText
})   

web3.eth.getTransaction(transactionHash)

But they will obviously not provide me with what I want.

Question: Is what I am describing a custom smart contract that I will need to build or is what I'm describing not possible at all, even through the use of a smart contract?

I understand that the role of smart contracts is to generate transactions whereas I'm thinking of a smart contract that would use an existing transaction and attach some data to it before it is sent back to me.

If it is possible, and since I don't have any experience with smart contracts, could you give me some starting points? Not as to how to build a smart contract, I know there are tutorials for that, but as to how to start building this particular smart contract. I'm not asking for the actual code but more of a high level explanation if possible so that I can somewhat visualise its structure/logic and use it as a blueprint. Again, I understand that this might not be possible at all :)

Please note that even though my use case might sound weird I don't want to go into too many details that could sidetrack the main objective of the post.

I'm basically looking for a way to retrieve transactions I've created but also attach some extra dynamic information to them at the moment of retrieval. That information will obviously not be stored in the transactions as they are immutable. It will be information that will be lost as soon as I read it and created anew the next time I request that transaction.

2 Answers 2

1

You can code a smart contract. On a high-level, you first code a smart contract that has two functions. One that takes as input your transaction. Let's call this function inputTransaction. You could have another smart contract function called appendData which appends some data to your transaction and emits a smart contract event that contains both your transaction and the appended data. To get what you want to be done, you should do the following:

  1. First deploy your custom smart contract on a blockchain (i.e. Ethereum)
  2. Invoke inputTransaction in the smart contract and parse the transaction (refer to web3 docs on how to invoke smart contract functions.)
  3. When you require something to be appended to the transaction invoke the appendData function and fetch the receipt of that transaction asynchronously (again refer to web3 docs on how to send transactions and wait for their receipts asynchronously).
  4. The receipt will contain the event which could be retrieved and read by you. This will contain both your transaction and the appended data.
2
  • I guess invoke smart contract functions is the key to my problem. If I can use the web3 API to invoke functions of my contract and have them return my transaction with the appended data then this is it. Thanks (!) May 27, 2022 at 14:47
  • 1
    yes, you can get what you want to be done, in the way I mentioned in my answer. I recommend writing the contract in Solidity, deploying it on ganache for example, and testing it with web3js. Although the implementation tech stack is up to you.
    – Deepal
    May 27, 2022 at 15:04
0

before it is sent to me, should not reside on my server.

No. This is not how blockchains work.

Please read more information here on why smart contracts don't communicate with servers.

3
  • So you're saying that if I deploy a smart-contract that handles transactions on the Ethereum blockchain, I cannot have that same contract execute some extra logic whenever I query one of those transactions from the blockchain and have that contract send me back that extra bit of information ? (to clarify I do not wish to edit the transactions, I know that is impossible. May 27, 2022 at 13:28
  • 1
    Because the question is so much off-target, I recommend you to study the basics of smart contract programming before trying to ask questions. For that purpose, it is better to start with online tutorial than Q&A site. Because giving you starting point is impossible as you do not know the basics. May 27, 2022 at 14:00
  • 1
    I understand. I just wanted to know in advance if what I have in mind is possible because if it's not possible then there's no point in studying smart-contracts as I won't be using them as a solution to my problem. May 27, 2022 at 14:45

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.