Showing posts with label blockchain technology. Show all posts
Showing posts with label blockchain technology. Show all posts

Tuesday, January 24, 2023

Best beginner guide on distributed ledger technology - Articlesonblockchain

Best beginner guide on distributed ledger technology - Articlesonblockchain

Distributed Ledger Technology (DLT) is a form of digital record-keeping that uses a network of computers to store and share data. It is a type of distributed database that is maintained by multiple parties in a decentralised way. DLT is the foundation of cryptocurrencies like Bitcoin and Ethereum, but it can also be used to track and store other types of data, such as financial records, medical records, and legal documents.


What is a distributed ledger? 

 

A distributed ledger is a type of digital database that is shared across a network of computers. It is designed to be secure and immutable, meaning that it cannot be changed or deleted. All participants in the network have access to the same data, which is updated and validated in real-time as new transactions occur.

 

What are the advantages of distributed ledgers? 

 

The advantages of distributed ledgers include increased transparency, enhanced security, faster transaction times, and reduced costs. Additionally, distributed ledgers are resistant to tampering, making them more reliable than traditional databases.

 

How does distributed ledger technology work? 

 

DLT works by using a network of computers to store and share data. Each computer in the network keeps a copy of the ledger, which is regularly updated and validated by all participants. This ensures that the data stored on the ledger is accurate and secure.

 

What are some applications of distributed ledger technology? 

 

Distributed ledger technology (DLT) has a wide range of potential applications, some examples include:


Cryptocurrencies: Blockchain, the most well-known type of DLT, is used to create digital currencies such as Bitcoin.

Supply Chain Management: DLT can be used to create a tamper-proof record of all the transactions that occur within a supply chain, making it possible to trace the origin of goods and ensure that they are not counterfeit.

Smart Contracts: DLT can be used to create "smart contracts" which are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code.

Identity Management: DLT can be used to create a decentralized system for storing and verifying identity information, enabling individuals to have more control over their personal data.

Digital Voting: DLT can be used to create a secure, transparent, and auditable voting system that allows for remote voting and prevents voter fraud.

Financial Services: DLT can be used to increase the efficiency and reduce the cost of financial transactions by creating a shared database of financial assets and enabling real-time settlement of trades.

Gaming and Digital collectibles: DLT can be used to create unique digital assets that can be owned and traded by players, creating new revenue streams for game developers.

Real estate: DLT can be used to create a tamper-proof record of property ownership, making it easier to buy, sell, and transfer property.

These are just a few examples, but the possibilities for DLT are vast and new use cases are constantly being developed.

 

What are some of the challenges associated with distributed ledger technology? 

 

Distributed ledger technology (DLT) is a relatively new technology, and as such, it faces a number of challenges. Some of the main challenges include:


Scalability: As the number of users and transactions on a DLT network increases, the network can become slow and expensive to use. This is particularly an issue for blockchain, the most well-known type of DLT, which is currently facing scalability challenges.

Regulation: DLT is a decentralised technology, and it is not yet clear how it should be regulated. Some governments have taken a cautious approach and have banned or restricted the use of certain types of DLT, while others have embraced it.

Security: DLT is a secure technology, but it is not immune to hacking and other forms of cyberattacks. As the technology develops, it will be important to continue to improve the security of DLT networks to protect users' data and assets.

Interoperability: DLT networks are not currently able to easily communicate with each other, making it difficult for users to move assets and data between different networks. This can be a significant barrier to the widespread adoption of DLT.

Adoption: DLT is a complex technology, and it can be difficult for non-technical users to understand and use. To achieve mainstream adoption, it will be necessary to develop user-friendly interfaces and applications that make DLT accessible to a wider audience.

Energy consumption: Some of the public blockchain networks like Bitcoin and Ethereum are consuming huge amount of energy which is a significant environmental concern.

Privacy and Confidentiality: While the transparency and immutability of DLT is one of its key advantages, it also raises concerns about privacy and confidentiality. This is a significant issue for industries that deal with sensitive data, such as healthcare and finance.

Overall, DLT is a promising technology with many potential benefits, but it will require ongoing research and development to address these challenges and fully realize its potential.

 

Conclusion:


By understanding how distributed ledger technology works and its potential applications, you can begin to explore the possibilities of this revolutionary technology. Whether you’re a developer, investor, or just an enthusiast, DLT has the potential to revolutionise the way we exchange data, assets, and value.

Ultimate Introduction to Blockchain Technology - Articlesonblockchain

Ultimate Introduction to Blockchain Technology - Articlesonblockchain

Blockchain technology is a revolutionary technology that has been gaining a lot of attention recently. It is a distributed ledger technology that allows for secure, transparent, and immutable transactions between two or more parties. It is a decentralised system that does not rely on a central authority for verifying transactions. It is an open source platform, meaning anyone with the necessary coding skills can access the code and interact with it.


What is a Blockchain?


Blockchain is a distributed ledger technology that can be used to record transactions between two or more parties. It is a form of a digital ledger that stores data in blocks that are chained together. Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data. This data is stored across multiple computers or nodes, making it difficult to tamper with or corrupt. The nodes must come to a consensus to validate each transaction, ensuring its accuracy and validity.

How Does Blockchain Work?

 

Blockchain is a decentralised system, meaning that there is no central authority responsible for verifying transactions. Instead, the nodes in the network verify the transactions by coming to a consensus. This consensus is achieved through a process known as “mining.” Blockchain miners use specialised hardware to solve complex mathematical problems in order to validate the transactions. Once the miners have validated the transaction, it is added to the blockchain and can never be changed or reversed.



Let’s take an example of two users A and user B who are trying to make a transaction. The steps would be as follows:


Step-1: A initiates a transaction by creating a digital signature using their private key.

Step-2: The transaction is broadcast to the network and picked up by the miner.

Step-3: The miner verifies the transaction using A's public key and the digital signature.

Step-4: The miner then groups the transaction with other unconfirmed transactions into a block.

Step-4.1: The miner then competes with other miners to solve a complex mathematical problem called a "proof of work."

Step-4.2: The first miner to solve the problem gets to add the block to the blockchain, and in return, gets a reward in the form of newly minted bitcoins.

Step-5: Once the block is added to the blockchain, the transaction between A and B is considered confirmed.

Step-6: B can now check the blockchain to confirm that they have received the bitcoins from A.

Step-7: B can now spend the bitcoins in another transaction by following similar steps.


What are the benefits of Blockchain?


Blockchain technology offers several benefits that can improve efficiency, transparency, security, network distribution, traceability, and reduce costs. Some of the key benefits include:


Efficiency: Blockchain allows for faster and more secure transactions, reducing the need for intermediaries and streamlining processes.

Transparency: Blockchain provides a tamper-proof record of all transactions, making it easy to track and verify information.

Security: Blockchain's decentralised and distributed architecture makes it resistant to hacking and fraud.

Network distribution: Blockchain allows for decentralised networks, which can improve accessibility and reduce the risk of a single point of failure.

Traceability: Blockchain technology enables traceability of all transactions in the network, increasing accountability and enabling real-time tracking of goods and assets.

Reduced costs: Blockchain can reduce the need for intermediaries and streamline processes, resulting in cost savings.

Availability: Blockchain networks can be accessible globally, 24/7 with no downtime.

Automation: Blockchain smart contracts can automate many processes, reducing the need for manual intervention.

Decentralisation: Blockchain allows for the distribution of power and control, making the network more resilient and less vulnerable to manipulation.

Tokenisation: Blockchain technology allows for the creation of digital assets, such as tokens, which can be used as a means of exchange, representation of assets, or access to a network.


What are the realtime applications of Blockchain?


Blockchain technology has a wide range of potential applications as shown in the below picture:


[source: miro.medium]


Cryptocurrency: Bitcoin, the first and most well-known application of blockchain, allows for peer-to-peer transactions without the need for a central authority.

Supply Chain Management: Blockchain can be used to track products as they move through the supply chain, increasing transparency and efficiency. An example is IBM Food Trust, which uses blockchain technology to track the movement of food products from farm to store.

Voting Systems: Blockchain technology can be used to create secure and transparent voting systems, as votes can be recorded and tallied on the blockchain.

Digital Identity: Blockchain technology can be used to create secure digital identities, which can be used for a variety of purposes, such as logging into websites or accessing government services.

Real estate: Blockchain technology can be used to record and transfer property ownership, making the process more efficient and secure.

Banking: Blockchain technology can be used to increase the speed and security of financial transactions and settlement.

Healthcare: Blockchain can be used to securely store and share patient data and electronic medical records, allowing for better coordination of care and improved patient outcomes.

Gaming: Blockchain technology is being used to create new types of games, such as collectible card games that use non-fungible tokens (NFTs) to represent in-game items.

These are just a few examples of the many potential uses of blockchain technology. 


Conclusion:


Blockchain technology is an innovative and disruptive technology that has the potential to revolutionise many industries. It is a secure, transparent, and immutable technology that can be used to facilitate secure and efficient transactions between two or more parties. As the technology continues to evolve, more use cases for blockchain will be discovered and the technology will become even more accessible and useful.

Friday, December 30, 2022

7 Easy Steps to Setup and program a Ledger Smartcontract using Python Language

7 Easy Steps to Setup and program a Ledger Smartcontract using Python Language

From the analysis performed by Precedence Research, the blockchain technology market size is expected to reach USD 69.7 Billion by 2025 and USD 1593.8 Billion by 2030. Demand of the blockchain developers are increasing day by day. 

Growth Analysis of Blockchain Market:

Ledger - Growth Analysis of Blockchain Market

Image Source: Precedence Research

People coming from any Industry be it Electronics, Software, Medical, Mechanical… “You need to keep learning to stay up to date in the current market”. Being a software engineer, new programming languages or tools change very frequently, but today we are not going to learn any new programming language considering that you are aware of Python programming.

 

This post will explain the steps of deploying smart contracts using Python and make you understand on how to do it independently and concisely. Before we dig into the article, we need to understand few things explained below:

 

        - Python pre-requisites to deploy ledger Smartcontract 

        - About the libraries installation

        - Details of the Platform for performing blockchain operations


Python pre-requisites to deploy ledger Smartcontract:

About the libraries Installation:

 

Run the following commands to install:

  • Web3.py:  $ pip install web3
  • Solcx:       $ pip install py-solc-x
  • Eth_Utils:  $ pip install eth-utils==1.1.2
  • Dotenv:     $ pip install python-dotenv

 

Note: When installing you might find issues related to library version. If you observe, try with below to resolve:


$ pip install web3==4.1.9

$ pip install eth-utils==1.10.0

 

Details of the Platform for performing blockchain operations:

 

No need to worry if you do not have prior experience or knowledge on Solidity, I have an article on this and it a “16 Step Guide to Setup and program a Ledger Smartcontract using Solidity” will help you understand step by step, till then you can use the sample file “SimpleStorage.sol” – Download

 

We will be using “Gananche” tool to perform blockchain operations locally before deploying. This tool is used to test blockchain transactions, inspect changes etc.. (Tool has both CLI and GUI)

 

 

7 Steps to Setup and program Smartcontract:

 

STEP – 1: Importing Libraries

 

from eth_utils import address

from web3 import Web3

import os

from solc import compile_standard, install_solc

from dotenv import load_dotenv

import json

 

STEP – 2: Reading the .SOL file using python

 

with open("./SimpleStorage.sol", "r") as file:

    simple_storage_file = file.read()

 

STEP – 3: Compiling the Smartcontract

 

For this Step we use “py_solc_x” library to use standard compile function. This is used to break the code into Assembly Language, which is much closer to Machine Language for execution.

 

Before going into code, we need to understand 4 parameters used to compile Smartcontracts:

 

lauguage: Solidaty language to understand the details of the Smartcontract

 

sources: Smartcontract file, content and variables used to store information of Smartcontract

 

outputSelection: To get information related to ABI, Metadata, Bytecode and its sourcemap.

 

solc_version: This is the version used in the Smartcontract code

 

Once we understand the above information, Open the file and save it into JSON formatted file:

 

compiled_sol = compile_standard(

    {

        "language": "Solidity",

        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},

        "settings": {

            "outputSelection": {

                "*": {

                    "*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]

                }

            }

        },

    },

    solc_version="0.6.0",

)

 

with open("compiled_code.json", "w") as file:

    json.dump(compiled_sol, file)

 

 

STEP – 4: Extraction (ABI & Bytecode from Solidity Smartcontract)

 

Bytecode contains the information for code execution. It includes the key commands in assembly language that are executed at low-level or machine-level instead of the whole smart contract. In other words, this is the code that is executed by Ethereum Virtual Machine (EVM) and which governs the working of the smart contract file.

 

Below code is in JSON format, this is from the compiled contract file

 

# get bytecode

bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][

    "bytecode"

]["object"]

 

Besides, ABI is “Application Binary Interface” this is also an important piece of information for a Smartcontract.

 

ABI in Smartcontract is responsible for interaction between methods and structures, it is similar to Application Programming Interface (API). In the above compiled JSON object if you print the data, you will find ABI with Smartcontract file inputs, names, rdata types and outputs etc..

 

# get abi

abi = json.loads(

    compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["metadata"]

)["output"]["abi"]


STEP – 5: Local Ethereum Blockchain connection using Ganache

 

Install Ganache tool, use Quick Start and get the information from the tool.


Ledger Ganache - Transaction


w3 = Web3(

    Web3.HTTPProvider("HTTP://127.0.0.1:7545")

)

chain_id = 1337

my_address = "0x23959D4e00640f2D152dA3F96474504e63Aa6d2D"

# private_key = os.getenv("PRIVATE_KEY")

private_key = "0x4d08735ff981fa51e9c56c79c99d121c9f66754c27926ca5014fdaa2d71e904f"

 

Few things to consider here:

  • Add a 0x before pasting the private key from Ganache.
  • It is good practice not to leave your private key in the code. Instead, create a new file–.env. In this file, write “PRIVATE_KEY=0x,” and after 0x, paste in the private key.
  • To find out the Chain IDs of different blockchains, head here.

 

STEP – 6: Performing Smartcontract Transaction using Python 

 

This is the part where you need to keeps your eyes wide open and do not get disturbed. 

 

initialize the smart contract in Python by setting parameters for ABI and Bytecode

 

# initialize contract

SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)

 

Next it is important to know about Nonce - it’s an arbitrary number that can be used once in blockchain communication. Nonce tracks the number of transactions with help of function – “getTransactionCount” on the addressed used.

 

nonce = w3.eth.getTransactionCount(my_address)

 

Few things to consider here:


After creating Smartcontract in Python, there are 3 more things to do – 

Ø  Build the transaction

Ø  Sign the transaction

Ø  Send the transaction

 

Build the Ledger Transaction:

 

Web3.py has information we passed related to chainid, address of sender, and a nonce. Pass this information as variables so we can use it when required

 

tx = SimpleStorage.constructor().buildTransaction(

    {

        "chainId": chain_id,

        "gasPrice": w3.eth.gas_price,

        "from": my_address,

        "nonce": nonce,

    }

)

 

Sign the Ledger Transaction:

 

To sign the transaction we need to use the private key of the address of the sender, hence it is advised to store the private key separately instead of using directly in the code. Here we use the transaction build and private key as show below:

 

signed_tx = w3.eth.account.signTransaction(tx, private_key=private_key)

 

Send the Ledger Transaction:

 

This step uses the send_raw_transaction function with signed transaction parameter as shown below:

 

tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)

tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

print(f"Contract deployed to Infura at address {tx_receipt.contractAddress}")

 

Ledger - Ganache - Transaction 2

STEP – 7: Deploying Smartcontract using Python

 

We have arrived to last step which we are waiting from the starting of this article, but all the above steps are mandatory to get to this point.

 

To work with or interact with smart contracts in Python, you need ABI and address. 


Ledger Ganache transaction created

There are 2 ways to interact with blockchains – call and transact

 

Call: The functions in smart contracts that don’t make state changes or the view functions.

 

Transact: The function in smart contracts that do make state changes.


Ledger Pycharm code execution

To make a state change, you must:

  1. First build a transaction,
  2. Then sign the transaction
  3. Then send the transaction
  4. Once the store function has been “transacted,” 

call the retrieve function to fetch the value, function is used in below code to work with deployed contracts

 

simple_storage = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi)

print(f"Initial stored value at Retrieve {simple_storage.functions.retrieve().call()}")

new_transaction = simple_storage.functions.store(25).buildTransaction(

    {

        "chainId": chain_id,

        "gasPrice": w3.eth.gasPrice,

        "from": my_address,

        "nonce": nonce + 1,

    }

)

signed_new_txn = w3.eth.account.signTransaction(

    new_transaction, private_key=private_key

)

tx_new_hash = w3.eth.sendRawTransaction(signed_new_txn.rawTransaction)

print("Sending new transaction...")

tx_new_receipt = w3.eth.waitForTransactionReceipt(tx_new_hash)

 

print(f"New stored value at Retrieve {simple_storage.functions.retrieve().call()}") 


Print Friendly and PDF

Friday, December 23, 2022

Ledgers: Uses of Blockchain Smartcontracts - Article

Ledgers: Uses of Blockchain Smartcontracts - Article

Uses of Blockchain Smartcontracts Ledgers


Uses of Smart Contracts:


Blockchain Smartcontracts can be used in almost all fields, starting from healthcare to supply chain to financial services. Some examples are as follows:


Voting system:


Smartcontracts provide a secure environment making the voting system less susceptible to manipulation. Votes using smartcontracts would be digital ledger-protected, which is extremely difficult to decode.


Moreover, smartcontracts could increase the turnover of voters, which is historically low due to the inefficient system that requires voters to line up, show identity, and complete forms. Voting, when transferred online using smartcontracts, can increase the number of participants in a voting system.


Healthcare Industry:


Blockchain can store the encoded health records of patients with a private key. Only specific individuals would be granted access to the records for privacy concerns. Similarly, research can be conducted confidentially and securely using smartcontracts.


All hospital receipts of patients can be stored on the blockchain and automatically shared with insurance companies as proof of service. Moreover, the digital ledger technology can be used for different activities, such as managing supplies, supervising drugs, and regulation compliance.


Supply chain Industry:


Traditionally, supply chains suffer due to paper-based systems where forms pass through multiple channels to get approvals. The laborious process increases the risk of fraud and loss.


Blockchain can nullify such risks by delivering an accessible and secure digital version to parties involved in the chain. Smartcontracts can be used for inventory management and the automation of payments and tasks.


Financial services Industry:


Smartcontracts help in transforming traditional financial services in multiple ways. In the case of insurance claims, they perform error checking, routing, and transfer payments to the user if everything is found appropriate.


Smartcontracts incorporate critical tools for bookkeeping and eliminate the possibility of infiltration of accounting records. They also enable shareholders to take part in decision making in a transparent way. Also, they help in trade clearing, where the funds are transferred once the amounts of trade settlements are calculated.

Cited Source: https://corporatefinanceinstitute.com/resources/valuation/smart-contracts/

Print Friendly and PDF