This time, how to upload data to bsv blockchain with polyglot and bitsv.
What is polyglot and bitsv?
Basically uploading data to the blockchain requires a deep understanding of networks such as p2P, so it is very difficult for engineers who have not programmed since the early days of the Internet.
Polyglot is a Python library that makes it easy to upload various data to the BSV blockchain, even for engineers who do not have enough network knowledge like me.
polyglot won the 3rd place at the 1st BSV Hackathon, and anyone who can use python can easily upload data to the BSV blockchain.
upload data to bsv blockchain with polyglot and bitsv
First install polyglot and bitsv on your Pyhon.
pip install bitsv pip install polyglot-bitcoin
And if the installation is successful, import them
# import library import bitsv import polyglot
prepare a secret key expressed in WIF .Then, check the bitcoinsv that the private key holds with ‘get_balance()’
my_key = bitsv.Key('YourPrivateKeyGoesHere') # Defaults to "main" network my_key.get_balance() 10000000 # satoshis
First, generate a transaction to send a normal bsv using polyglot and bitsv.Remittance can be specified in either BSV or USD.
# Can include a long list of tuples as outputs outputs = [ # Donate to AustEcon! (Currency conversion via api) ('1PdvVPTzXmo4cSs68HctLUxAdW917UZtC8', 0.10, 'usd'), # $USD 0.10 as bsv ('1PdvVPTzXmo4cSs68HctLUxAdW917UZtC8', 0.0001, 'bsv') ] my_key.send(outputs)
Then, I will explain the data upload of the subject. Uploading data to the BSV blockchain will change the protocol used when the data size is 100kb or less or 100kb or more.
This is because the maximum amount of data that the BSV blockchain can upload at one time is 100 kb. For 100kb or less, use the protocol 「b: //」. For 100kb or more, use the protocol 「bcat: //」. (Both were developed by unwriter) This time we will introduce about uploading data under 100kb for the time being.
Image file to be uploaded this time (6kb) ↓
import polyglot uploader = polyglot.Upload('your private key goes here in WIF format') # Optional parameters shown for completeness are populated from the file path by default file = "C:\\Users\\user_name\\Downloads\\xxxxx.jpg" # Uploading data to the BSV blockchain by b protocol res = uploader.upload_b(file, media_type=None, encoding=None, file_name=None)
The data upload is now complete.The variable ‘res’ stores the transaction ID of this data upload.
Whether the upload was successful that You can check with the ‘bitstagram（https://bitstagram.bitdb.network/) ‘ that developed by unwritter, which can check the contents of the image file uploaded with ‘b’.
# Check transaction contents using API of blockchair.com/ import requests import json # tx_hash ='c3e42519a7a76e81cdf26470decf2356c21f4e1b2bfacfcc1e409e6ec88cf714' tx_hash = res['data']['txid'] # Get transaction contents with requests and blockchair.com's API r = requests.get( 'https://api.blockchair.com/bitcoin-sv/dashboards/transaction/' + tx_hash) r = json.loads(r.text) # Extract binary data uploaded from api response img_binary = r['data'][tx_hash]['outputs']['script_hex'] # Check the Variable'img_path' with print print(img_binary)
Uploading data over 100kb with ’bcat’ is a bit cumbersome, so I will explain it later in another article.
This is how to upload data to BSV blockchain with polyglot.
BSV mined a 2GB big block in the July 2019 update. This is great that neither BTC nor BCH could do.
I don’t know if csw is really Satoshi Nakamoto, the inventor of Bitcoin. However, the BSV he is developing has mined a 2GB big block exceeding the BTC block size of 32MB in 2009 and revived OP_CODE, which was abolished when introducing Segwit, and reviving smart contracts and tokenized.There is no doubt that BSV is on the path that bitcoin was supposed to be.
I am convinced that blockchain was originally aimed at increasing the block size so that it can be scaled, and creating various applications such as Dapps on the blockchain and the Internet itself.
Convenient applications are being developed every day at BitcoinSV by excellent developers including Mr. Unwritter, which is very exciting.