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