Broadcasting custom operations into STEEM blockchain

in steem •  7 years ago  (edited)

Let's say I want to store my notes for the books I have read, on a decentralized blockchain.

Creating a post may not be the perfect fit since generally notes are very short-form content and you don't expect everyone to see it on interfaces like Steemit or Busy.

custom_json


Steem blockchain has a custom_json operation which you can actually post any type of JSON data into the blockchain. It's not really a post or comment so it doesn't show up in the Steemit.

Let's post a quote from the book "Code Complete".

from steem import Steem
from steem.transactionbuilder import TransactionBuilder
from steembase import operations
s = Steem(nodes=["https://rpc.buildteam.io"],
          keys=["posting_key"])
account = "emrebeyler"
ops = [
    operations.CustomJson(**{
        "from": account,
        "id": "notes.books",
        "json": [
            'add-quote',
            {
                "book": "Code complete",
                "quote": "Reduce complexity. The single most important reason "
                         "to create a routine is to reduce a program's "
                         "complexity. Create a routine to hide information"
                         " so that you won't need to think about it."
            }
        ],
        "required_auths": [],
        "required_posting_auths": ["emrebeyler"],
    }),
]
tb = TransactionBuilder()
tb.appendOps(ops)
tb.appendSigner(account, "posting")
tb.sign()
tb.broadcast()

And after a couple of quotes, if I ever want to see my quotes:

import json
from steem.account import Account
account = Account('emrebeyler')
for custom_json in account.history_reverse(filter_by=["custom_json"]):
    if custom_json["id"] == "notes.books":
        action, data = json.loads(custom_json.get("json"))
        print("Book: %s\n Quote: %s" % (data["book"], data["quote"]))

Which will result like that:

Pretty cool, huh? I am not sure if any of the 3rd party apps utilizing custom_json yet but it seems Hivemind will utilize it for the communities feature.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

This is pretty useful. I think jussi will use this to batch transactions if I am not mistaken.

Cool! @randowhale used this in the past for the payout distribution to delegators, see here for example

For someone that scripts, this is very interesting. I've been wanting to create a rudimentary Steem RPG game and think this may be a good method of storing character stats.

Also, with @flagawhale, one of the difficulties I face is getting the rshares Delta's from the previous battle update. For background, we periodically pull rshares on those that downvote Haejin and slate it for rewards. I don't want to reward the values that had not changed and instead of fiddling around in Excel. Maybe this would be a better alternative as I would be able to run comparisons via python.

Thanks for sharing. Think this is going to help a lot to automate our process.

Sounds like a good use case! :)

Thx a lot!

Hello from the future :)

Can you post how to do this with beem?

Ask this question on Python community ;)

Haha ... I would but then it will end up as a post on my feed ... and it will look like spamming a bit ... btw ... I found out how to do this :)

Slowly learning :)

Nice!

Hi @emrebeyler!
I gladly voted you as witness. Good luck!

I will follow you and I hope you can find the opportunity to support one of my projects for making growin' up @steempostitalia, the italian community on Steemit: The Best Power Up of the Week
I think that could be really important, the project is already having great success.
If you are interested in starting any kind of collaboration with us, contact me.

Thank you so much!

See you soon
Girolamo

Thank you! I will have a look to your power-up challenges.

your every information is very important for steemit members.Thanks for share with us.

Wow, thanks for sharing that piece of wisdom. I saw the transaction type and was wondering what one can do with it. Now I know. I'm sure I can use this for SteemDesk in the future.

very nice and helpful information to all of us @emrebeyler.
thank you for sharing your knowledge, hopefully healthy always for you who can share knowledge again

I have a question. Is this custom json upvotable and can can you earn SBD from this data that you store on the blockchain ?

No, that's the downside. It's not upvote-able content.

Great! Thanks!

Good!@

it's useful!

I appreciate you for this post. Thank you over a year later ^>^

hi i am facing the below error:

AttributeError: module 'steem' has no attribute 'steemd'

 20     if not _shared_steemd_instance:
 21         if sys.version >= '3.5':

---> 22 _shared_steemd_instance = stm.steemd.Steemd(
23 nodes=get_config_node_list())
24 else:

I got your message about voting for witness. I did.

Following you. Im working towards learning basic programming, perhaps I'll pick something up from your blog.