0

I want to write transactions where two things matter: i) sender's address ii) SHA 256 hash that I want to write

How can I achieve that?

I looked into Bitcoin's transaction types and found out that OP_RETURN is used to write data like transactions and that it is a non-payment type of transaction. I want to know what is the equivalent of this in the Substrate chain?

Aviral Srivastava
  • 4,058
  • 8
  • 29
  • 81

1 Answers1

1

When you say two things matter, I'm guessing you mean those are the input parameters. The sender's address is recoverable using Substrate's ensure_signed function. And the SHA256 hash should be passed as a parameter.

You would likely benefit from following the Proof of Existence tutorial in which the learner builds a dApp that tracks proofs of a file's existence. The proof is merely a hash of the file.

JoshOrndorff
  • 1,591
  • 9
  • 19
  • Yes, I have followed that tutorial and I revisited it again. Any idea of how I can do that without building a dApp? My complete objective is to upload a file to S3 and store its hash on the Substrate chain. Shawn suggested that I should not bring the file in the blockchain and so I am creating an outside service to do this. Hence, I need to know the functions/way that can emit such an event. Can you help me with that? – Aviral Srivastava Mar 13 '20 at 15:39
  • This is a very confusing response @AviralSrivastava. If you are building an outside service, the Substrate tag is not really the best place to get help. Beyond that, once you have built a service that can upload a file, you should generate some "well known account" for that software, and have that service submit transactions to the blockchain just like any other user would. – Shawn Tabrizi Mar 13 '20 at 16:53
  • Apologies. I will rephrase. I am intending to create a library/service that would upload the file on S3, create its hash and write that hash on the Substrate chain. Writing such transactions would require user authentication(user of that substrate chain). I am struggling with this step: how to write transactions on the substrate chain from outside of it in Rust? Did I make it clear this time? – Aviral Srivastava Mar 13 '20 at 19:22
  • It sounds like the proof of existence dApp is exactly what you're looking for. To submit transactions from outside the rust code, I recommend the Polkadot JS Api. Here are its docs https://polkadot.js.org/api/start/ Regarding user authentication, do you mean that only a pre-approved set of users will use the chain? If so, check out this pallet https://github.com/gautamdhameja/substrate-account-set – JoshOrndorff Mar 13 '20 at 19:34
  • "To submit transactions from outside the rust code,". No I want to write the code in Rust only. I want to submit transactions outside of the chain _i.e._ interact with the chain from outside just like [this](https://github.com/scs/substrate-api-client) library does in many examples. – Aviral Srivastava Mar 13 '20 at 19:41