1. UNIT V
BLOCKCHAIN APPLICATIONS
Smart contracts, Truffle Design and issue- DApps- NFT. Blockchain
Applications in Supply Chain Management, Logistics, Smart Cities,
Finance and Banking, Insurance,etc- Case Study.
2. Applications of Blockchain Technology in Various
Industries
Financial Services
Healthcare
Government
CPG and Retail
Travel and Hospitality
3. SMART CONTRACTS
Smart contracts are digital contracts stored on a blockchain that
are automatically executed when predetermined terms and
conditions are met.
A smart contract works in the same way as a traditional contract
while also automatically enforcing the contract.
Smart contracts are programs that execute exactly as they are
set up (coded, programmed) by their creators.
6. HOW DO SMART CONTRACTS WORK?
A smart contract is just a digital contract with the security coding of the blockchain.
It has details and permissions written in code that require an exact sequence of events to
take place to trigger the agreement of the terms mentioned in the smart contract.
It can also include the time constraints that can introduce deadlines in the contract.
Every smart contract has its address in the blockchain. The contract can be interacted
with by using its address presuming the contract has been broadcasted on the network.
The idea behind smart contracts is pretty simple. They are executed on a basis of simple
logic, IF-THEN for example:
IF you send object A, THEN the sum (of money, in cryptocurrency) will be transferred to
you.
IF you transfer a certain amount of digital assets (cryptocurrency, for example, ether,
bitcoin), THEN the A object will be transferred to you.
IF I finish the work, THEN the digital assets mentioned in the contract will be transferred to
me.
7. Smart Contract Working
Identify Agreement: Multiple parties identify the cooperative opportunity and desired
outcomes and agreements could include business processes, asset swaps, etc.
Set conditions: Smart contracts could be initiated by parties themselves or when certain
conditions are met like financial market indices, events like GPS locations, etc.
Code business logic: A computer program is written that will be executed automatically
when the conditional parameters are met.
Encryption and blockchain technology: Encryption provides secure authentication and
transfer of messages between parties relating to smart contracts.
Execution and processing: In blockchain iteration, whenever consensus is reached
between the parties regarding authentication and verification then the code is
executed and the outcomes are memorialized for compliance and verification.
Network updates: After smart contracts are executed, all the nodes on the network
update their ledger to reflect the new state. Once the record is posted and verified on
the blockchain network, it cannot be modified, it is in append mode only.
9. CHALLENGES OF SMART CONTRACTS
No regulations
Difficult to implement
Immutable
Alignment
10. TRUFFLE IN BLOCKCHAIN
Truffle is a development environment, testing framework, and asset
pipeline for building decentralized applications (dapps) on the
Ethereum blockchain.
Truffle has various advantages
Automated Contract Testing
Scriptable Migration and Deployment
11. TRUFFLE SUITE
Truffle is a leading development framework that simplifies the process of
building and deploying enterprise blockchain applications.
With its powerful suite of tools, Truffle enables businesses to create
robust, scalable solutions tailored to their unique needs.
Truffle Suite offers a comprehensive answer to all dApp developers with
a collection of powerful tools to facilitate smart contract development
on the Ethereum blockchain.
12. BASIC ROLES OF EACH COMPONENT OF TRUFFLE SUITE
Truffle is the smart contract development framework.
Ganache helps you in setting up a personal Ethereum blockchain for
development and testing on a local network.
Drizzle serves as a repository of ready-to-use components and an integral
tool in the development of dApp user interfaces.
13. GANACHE
Ganache is a personal blockchain for rapid Ethereum and Filecoin distributed
application development. It can be used across the entire development cycle;
enabling to develop, deploy, and test
dApps in a safe and deterministic environment.
14. DRIZZLE
Drizzle is a collection of front-end libraries that make writing
dapp front-ends easier and more predictable.
The core of Drizzle is based on a Redux store, so you have
access to the spectacular development tools around
Redux.
Drizzle is the fundamental package that handles contract
and account creation. This means the standard bundle
includes extra contract features.
15. SOME KEY PROPERTIES OF DRIZZLE
Stores: Drizzle maintains a library of React components
often used in dApps.
Reactive Datastore – Drizzle is built around a Redux store.
Drizzle also synchronizes transactions, contracts, etc.
Drizzle is a suite of libraries built on the Redux store. Its
modular design makes dApp UI creation more
accessible and customizable
16. USE OF TRUFFLE FOR BLOCKCHAIN
Truffle is a popular development framework for building
decentralized applications (dApps) on the Ethereum
blockchain.
It simplifies the process of deploying smart contracts,
managing interactions with the blockchain, and building
full-stack decentralized applications.
17. KEY REASONS TO CHOOSE TRUFFLE
1. Comprehensive Development Framework
2. Easy Smart Contract Deployment
3. Test and Debugging Tools
4. Integration with Ganache
5. Interactive Console
6. Support for Multiple Networks
7. Truffle Suite Ecosystem
8. Ease of Use
9. Active Community and Documentation
10. Security
18. CREATING DAPPS USING THE TRUFFLE FRAMEWORK:
dApps (Decentralized Applications) are applications
that do not rely on traditional servers. Instead, dApps
make use of Blockchain to host the data traditionally
stored on the servers.
The data is stored across the network of nodes connected to the
Blockchain. Various tools and frameworks are used to write full-
stack, decentralized applications.
One such popular framework for writing dApps using the Solidity
programming language is Truffle.
20. Step 1: Setting up the Development Environment:
The requirements before starting a Truffle project are as
follows:
Node.js
Ganache — For simulating a Bl ockchain locally.
Metamask — For handling Blockchain transactions via the
browser.
To set up the Truffle framework, run the following command:
npm install -g truffle
21. Step 2: Use a Truffle Box to generate boilerplate code:
To simplify the process of creating a dApp in Truffle,
instead of manually creating the files and including the
dependencies, you can use a Truffle Box.
A Truffle Box provides useful boilerplate code with which
you can directly start designing your dApp. These “boxes”
also contain other useful components, such as commonly
used Solidity Contracts, libraries, front-end views, etc.
truffle unbox pet-shop
truffle unbox react
truffle unbox pet-shoptruffle unbox react
22. Step 3: Writing the Solidity Smart Contracts:
Once a truffle box is downloaded and unpacked, it creates
a Truffle specific directory structure. The general structure of a
Truffle project is shown in the figure below:
The contracts directory, all the Solidity smart contracts are written and
stored as .sol files.
The migrations directory contains code to migrate and deploy the
designed contracts.
node_modules directory stores all the required node dependencies
to run the project.
src directory is used to store the front-end components of the project,
such as HTML and CSS files.
test directory stores the unit tests written by the developer.
truffle unbox pet-shoptruffle unbox react
23. Step 4: Compile and Migrate the Contracts:
Once the contracts have been written, we can compile and then
migrate them to store them on our blockchain. To compile a Solidity
contract in Truffle, run the command
truffle compile
Once successfully compiled, the contracts are converted into
bytecode which is executed by the Ethereum Virtual Machine (EVM).
After successful compilation, the contracts need to be saved on the
Blockchain such that users may access the functions provided by the
contract.
Once migrated to the Blockchain, each deployed contract is
assigned a unique address to reference its location on the
Blockchain
truffle unbox pet-shoptruffle unbox react
24. Step 5: Writing Unit Tests:
Test-Driven Development is a highly recommended approach in
all scopes of software development. It is of paramount
importance in the case of dApps.
By design of the blockchain, changes once made to the
blockchain are stored permanently and immutably on the chain.
. Unit Testing in Truffle can be done with the help of the Chai and
Mocha libraries, which provide a range of assertions and other
tools to perform testing. Once written the test are run by
executing,
truffle test
truffle unbox pet-shoptruffle unbox react
25. Step 6, 7: Creating a UI and integrating with the contracts:
The UI design of the dApp is done as usual using tools and languages like
HTML, CSS, Bootstrap, JavaScript, etc.
To interface the front end with the deployed contracts, we rely on the web3
JavaScript library.
Using web3js, we can instantiate the deployed Ethereum contracts inside a
front-end JS file and subsequently call functions and exchange data with
the blockchain
Step 6, 7: Creating a UI and integrating with the contracts:
The UI design of the dApp is done as usual using tools and languages like
HTML, CSS, Bootstrap, JavaScript, etc. To interface the front end with the
deployed contracts, we rely on the web3 JavaScript library. Using web3js,
we can instantiate the deployed Ethereum contracts inside a front-end JS
file and subsequently call functions and exchange data with the
blockchain
truffle unbox pet-shoptruffle unbox react