Hi Guys!!...
In this we will do multiple stuffs starting from creating wallet addresses to building python-based apps.
For this, we don't have to download the entire bitcoin-blockchain. We shall be fetching the API provided by Blockchain.info.
Let's get started....
Follow the steps:
conda install pip in your command prompt (for Windows).pip install bitcoin to install bitcoin in your system.
This Py-bitcoin fetches the data from "Blockchain.info" API.
Here, Python coding can be done in 2 ways: -
Command prompt -
Jupyter notebook -
Now, the notebook opens in the browser as follows:
use commands in the notebook -
Please, find the code below:
# import bitcoin
from bitcoin import*
# Generate private key
my_private_key = random_key()
print("My private key: " + my_private_key)
# Generate public key
my_public_key = privtopub(my_private_key)
print("My public key: " + my_public_key)
Here, are a few basic commands to use Bitcoin protocol.
First, we need to import the bitcoin library like this -
# import bitcoin
from bitcoin import*
my_private_key = random_key()
print("My private key: " + my_private_key)
my_public_key = privtopub(my_private_key)
print("My public key: " + my_public_key)
my_address = pubtoaddr(my_public_key)
print("My address: " + my_address)
This require multiple private-public keys.
Application: In organizations, suppose there is a account accessed by multiple members. Suppose, someone wants to make any transaction using that wallet address. In this case, we can use multi-signature wallet in order to unanimously decide on transactions happening from the company's wallet address. Hence, it would requrie the signature of each member. Therefore, account security is enhanced.
# Create private keys
private_key1 = random_key()
private_key2 = random_key()
private_key3 = random_key()
# Create public keys
public_key1 = privtopub(private_key1)
public_key2 = privtopub(private_key2)
public_key3 = privtopub(private_key3)
my_multi_sig = mk_multisig_script(public_key1, public_key2, public_key3, 2, 3)
my_multi_address = scriptaddr(my_multi_sig)
print("My multi signature wallet address: " + my_multi_address)
Through this function, we will see the bitcoin received (unit is in satoshi)
Code -
# a valid address
valid_address = "13bUJhSbGLvkLK2xHf3mUqR7eXhQ1Uzg8Z"
print(history(valid_address))
Code -
# a valid address
valid_address = "1Nh7uHdvY6fNwtQtM1G5EZAFPLC33B59rB"
print(history(valid_address))
That's it for now.