Transfer Hive Or HBD Using Beem

in LeoFinance3 years ago (edited)

beem_transfer.png

One of the best features of Hive blockchain is fast and free asset transfers. These days HBD has achieved a practical and reasonable peg to USD. This creates opportunities to use Hive blockchain in real world applications. Combination of fast & free transactions and true algorithmic stable-coin makes Hive a powerful blockchain and a network.

Most of use have transferred Hive native coins like Hive and HBD using various front-end applications like HiveBlog, PeakD, Ecency, etc. True power of Hive is revealed when we transfer funds programmatically with python or other programming language. I like python. Beem is a library to interact with Hive blockchain. In this post I would like to share how easy it is to send Hive or HBD using Beem.

Let's take a look at the following code:

from beem import Hive
from beem.nodelist import NodeList
from beem.account import Account
import getpass
import time

def main():
    nodelist = NodeList()
    nodelist.update_nodes()
    nodes = nodelist.get_hive_nodes()

    wif = getpass.getpass(prompt="Enter your Hive account active key:")
    #wif = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    hive = Hive(node=nodes, keys=[wif])
    account = Account('geekgirl', blockchain_instance=hive)
    for i in range(100):
        account.transfer('librarian', 0.001, 'HBD', 'book'+str(i+1))
        time.sleep(3)
    print('Transfers are complete!')

if __name__ == "__main__":
    main()

As you can see it is very simple to send funds using Beem. The code above make 100 transfers to the same account with the same amount. Using the same methodology, we can send funds to hundreds, thousands, or tens of thousands of accounts in no time.

First, we are getting a list of nodes that will be used to interact with Hive blockchain. If you know a reliable node, you probably could use a specific node. Alternatively, we can run our own Hive node.

Then, we need private active key to sing the transfers. One way to enter the private key is using getpass. This way we don't have to hard code the private keys into the code. Typing in the private keys into the code variable, may be a faster way when testing. However, it is not a good idea to keep the private keys in code. Make sure to keep your private keys secure.

Afterwards, we initiate a Hive instance. Using this instance we can now interact with Hive blockchain.

The line of code that sends the funds is this one:

account.transfer('librarian', 0.001, 'HBD', 'book'+str(i+1))

This line is used in a for loop, so that we can send transfers multiple times. If you are only sending one or few transfers, it is probably better not to use a for loop and type all the information in.

When transferring funds, we need four pieces of information. Account that will be receiving the funds, amount being sent, asset type - HIVE or HBD, and memo.

It is important to keep in mind that asset names should be typed in all capital letters, like HIVE or HBD. Memo is a message we want the receiver to see, or an explanation of the transfer. Memo can also be used as an invoice.

As you can see, we can send as little as 0.001 HIVE or HBD. You may have seen some people using transfers with this amount to send messages to accounts. There have also been occasions when such transfers we used to spam thousands of accounts. Spamming is not a good use for this powerful feature. If you really want to send messages to many people, maybe send higher amount, otherwise these messages won't even get read or just ignored as spam.

Another thing to keep in mind when sending multiple transfers is that using time.sleep(3). When I tested sending 10 transfers without time.sleep(3), everything worked ok. However, when I tried 100 transfers, then I received an error and code was interrupted at 30th transfer or so. That's why I added .sleep(3) between transfers, so that they don't get timed out. time.sleep(3) serves as a pause for 3 seconds before executing the next code or transfer in this case. I think less than 3 seconds should work. I just used 3 seconds to give enough time, and overall time doesn't take too long either for all transfers even with these pauses.

One of the use cases can be using Hive blockchain for payroll purposes. If I have a company of 200 employees and I decide to pay their salaries in HBD, this may be of benefit for the company and the employees. These transfers can be scheduled to be paid out on certain dates and executed fast and accurately. This may help removing expenses used for payroll services or accounting staff and employees can receive their salaries in a timely manner. Of course I am simplifying things in this example. There are more complex calculations involved in payroll like various taxes and fees. Even those can be done in a more efficient and transparent manner when using a blockchain.

At the same time there might be concerns of privacy for a private company disclosing their finances on a blockchain. Some employees many not want their salaries to be known to everybody. It may not be a good fit for all companies. Although there might be solutions for any privacy concerns too. It all depends on the value of privacy vs transparency.

Posted Using LeoFinance Beta

Sort:  

The more I see posts like this the more I suffer regret.

Really big traumatic regret.

Sometimes I feel I should just shutdown my life and rewind back in time.

I had the opportunity to learn python some 2 yrs ago.

But what did I do?

I threw it away for one stupid exam...

Now I know next to nothing about dev and web dev terms....

I haven't been the same since then...

It’s never too late to learn it bro if you still want to anyway ! Best Regards!!

I know... thats why i am on hive....

always giving me the necessary motivation.

Holy shit cool stuff! My nerd propeller starts spinning every time I see someone with a new and useful way to interact with the blockchain. Open source and we are just getting started.

Sometimes I envy you Devs. :D You guys can automate things with a few lines of code and we plebs just keep clicking buttons. 😂

Posted Using LeoFinance Beta

A very helpful information you ve shared here.
Now I have to learnt to use the knowledge.
It is obvious you like python.. 😊

I think payroll is an interesting case and I wonder if it will be a huge nightmare when dealing with taxes. Unless people have a dedicated account just for it, I just don't think mixing things up is a good idea but I guess you could make changes so it is more manageable.

Are there any companies that are currently paying their employees using Hive?

Posted Using LeoFinance Beta

That's a good question. I don't know.

geeky information indeed , thanks for the heads up always!!

Thank you for sharing with us. Really appreciate your work. I always learn something new from your blogs. I tried it before on the Steem blockchain but didn't try it here.
Which IDE do you use for Python programming? Previously I used Anaconda, but it crashed my hard drive.

I mainly use Visual Studio Code.

Thank you for your response.

Wait.. Peakd have a recurring feature aswell. Just saying xD
No need for coding

:) Nice way to transfer that HBD. and HIVE too. that's very cool!

Wow!!!
This is a really amazing way of transferring funds.

I really appreciate this keep up the good work @geekgirl

This post has been manually curated by @bhattg from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating your Leo power to @india-leo account? We share 100 % of the curation rewards with the delegators.

Please contribute to the community by upvoting this comment and posts made by @indiaunited.

Your content has been voted as a part of Encouragement program. Keep up the good work!

Use Ecency daily to boost your growth on platform!

Support Ecency
Vote for new Proposal
Delegate HP and earn more


The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.

Congratulations @geekgirl! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You distributed more than 27000 upvotes.
Your next target is to reach 28000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out the last post from @hivebuzz:

Feedback from the March 1st Hive Power Up Day
Our Hive Power Delegations to the February PUM Winners
Today is the beginning of a new Hive Power Up Month!

wow this information is useful

You seem to have a passion for programming. Very cool!!