This might be a possible duplicate with this.
I want to know a proper way to insert additional string with OP_RETURN and retrieve the transaction from block chain and decode it accordingly.
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
Essentially, one of the output scripts should be
OP_RETURN <the data you want to add>
Let me give an example. Say you want to add the string "Melons." to the blockchain.
That's... trickier. Bitcoin is not optimized for searching the metadata of transactions.
You might find our OP_RETURN libraries useful, for PHP and Python. If you look at the code you can also see exactly how they work.