You are on page 1of 13

R.V.

COLLEGE OF ENGINEERING,
BENGALURU-560059
(Autonomous Institution Affiliated to
VTU, Belagavi)

TITLE
EXPERIENTIAL LEARNING REPORT

Submitted by:

NAME OF THE CANDIDATE(S) ROLL NO


1.Rashmitha RVCE22BEI049/40

Faculty In charge
Name:Deepika Dash

Department: Computer science and Engineering

Subject: Elements of Blockchain Technology


R.V. COLLEGE OF ENGINEERING, BENGALURU - 560059
(Autonomous Institution Affiliated to VTU, Belgaum)

DEPARTMENT OF ELECTRONICS AND INSTRUMENTATION

CERTIFICATE
It is certified that the Experiential learning titled ‘Case Study on Blockchain development
tool called “Ganache”’ is carried out by Rashmitha(RVCE22BEI049), who are bonafide students
of R.V College of Engineering, Bengaluru, during the first semester, in the year 2022-2023. It is
also certified that all corrections/suggestions indicated for the Internal Assessment have been
incorporated in the report. The report has been approved as it satisfies the academic requirements
in respect of Experiential learning.

Marks awarded

Signature of Staff In-charge

Signature of Head of the Department


Table Of Contents:
1. Introduction
2. Literature survey
3. Demo
4. Test cases of Ganache
a. Writing smart contract
b. Deploying smart contract
c. Interacting with smart contract
d.Testing of smart contract
5. Implementation
6. Results and conclusion

Electronics and Instrumentation Engineering ii


RV COLLEGE OF ENGINEERING®,
BENGALURU-560059
Acknowledgement
We are indebted to our faculty, Deepika Dash, Department of Computer science and
Engineering, RVCE for his wholehearted support, suggestions and valuable advice
throughout our Experiential Learning Project  work.

Our sincere thanks to Dr. CH Renu Madhavi, Professor and Head, Department of
Computer Science and Engineering, RVCE for his support and encouragement.

We express sincere gratitude to our beloved Principal, Dr. K. N. Subramanya for his
appreciation towards this Experiential Learning Project  work.

Lastly, we take this opportunity to thank our family members and friends who
provided all the backup support throughout the project work.

Electronics and Instrumentation Engineering ii


Chapter 1:
Introduction

Web3 development has never been more in vogue with frantic activity in the Web3
and decentralized application (dApp) fields. This is partly due to the fact
that Web3 development still has not evolved to the same extent as traditional Web2
development. This, by extension, is not particularly strange, since as the dApp scene
remains somewhat in its infancy. However, Web3 development is still booming, and
there are some useful tools and platforms to aid development.

The Ganache Truffles tool can help in testing your smart contracts on a local
blockchain. As a result, you can easily avoid the unwanted transaction costs required
for testing and deploying contracts until you ensure that they are perfectly flawless.

Ganache is a local Blockchain development tool that is used to test and deploy smart
contracts

Chapter 2: Literature Survey

Electronics and Instrumentation Engineering ii


SL NO Title of the Journ Technology /Methodology
Paper al
Name,
Year
01 Ganache 101 The detailed introduction to
Blockchain- Blockc “What is Ganache in
a hains Blockchain?” showcases how
comprehensive Augus Ganache would revolutionize the
Guide t 05, smart contract development
2022 process. As a part of the Truffle
Suite, Ganache promises an
isolated personal blockchain
network you can use for testing
smart contracts. The
functionalities of Ganache enable
better productivity in terms of
speed of testing and deploying
contracts alongside the cost
benefits.
02 How to Log Smart contracts are immutable
develop, test Rocket programs stored on a blockchain.
and deploy - How to initialize truffle so that it
smart Fronte provides necessary utilities to
contracts nd develop and test contracts.
using ganache Analyt The most important method in
ics ganache is to create ganache
ethereum blockhain instance.

Electronics and Instrumentation Engineering ii


Chapter 3: Demo:

Ganache has two work space:


1. Ethereum Workspace
2. Corda Workspace
1. Ethereum Workspace:
a. Accounts: The default view showcases accounts created and the
balances associated with them.
b. Blocks: The blocks page presents an illustration of the details of
every block mined on the blockchain alongside the gas fees and
transactions involved.
c. Events: The page includes a list of all the events started since the
creation of the workspace, and Ganache works on decoding the events
facilitated by contracts in the Truffle project.
d. Transactions: The transaction page, as the name implies, points at a list
of all transactions operating against the blockchain network.
e. Logs: The Ethereum workspace on Ganache smart contract
testing blockchain would also feature an outline of the server logs, which
help in debugging.
f. Contracts: The Contracts page outlines all the contracts included
in the Ethereum workspace.

2. Corda Workspace:
a. Nodes: The page includes an outline of all the nodes and notaries
featured on the network.
b. CorDapps: The section presents a list of all the CorDapp jars you
have installed on the network.
c.Logs: The Logs section provides an outline of the different logs
for the Ganache server, notaries, and nodes, which serve promising use
cases in debugging.
d.Transactions: The Corda workspace in Ganache features a list of
all the transactions in this section.
e. Shell: The Shell section in the Corda workspace delivers Corda
CRaSH shell access to all nodes and notaries.

Chapter 4: Test cases:

4.1. Writing a smart contract:


Write the following code by creating a new file in contract folder called
first.sol

Electronics and Instrumentation Engineering ii


pragma solidity >=0.8.19 <19.8.1;
contract Hello{
address public owner=msg.sender;
string public message;
constructor() public{
message="Hello World";
This amrt contracy
}
modifier ownerOnly(){
require(
msg.sender == owner,
"This function is restricted to the contract's
owner");_;
}
function setMessage() public view returns (string memory){
return message;
}
function setMessage(string memory _message)
public
ownerOnly
returns(string memory)
{
require(bytes(_message).length>0);
message= _message;
}}
This smart contract stores message and only allows the owner of the
smart contract to change thie message . The smart also allows everyone
on the blockchain to be able to read this message. When the contract is
first deployed, the message stored on the blockchain in the smart contract
would be, “Hello World!”.

4.2 Deploying the smart contract to Ganache Ethereum local test


network:

Write the following code in migration folder by creating 2_initial_

const Hello= artifacts.require("./Hello.sol");


module.exports = function(deployer){
deployer.deploy(Hello);
};

Electronics and Instrumentation Engineering ii


Artifacts and deployer functions are taken care by Truffle.
truffle migrate --compile-all --reset --network ganache
reset: deploys the smart contract to the local test network. It will also
build the ABI and bytecode file that the Ethereum virtual machine is
capable of understanding.

Note: Before deploying smart contracts we have to create instance of


Ganache Blockchain and initialize truffle by making the following
change in truffle-config.js and fill out the correct port number:
module.exports = {
networks: {
ganache: {
host: “127.0.0.1”,
Port: 7545,
network_id: “*”
}}}

Electronics and Instrumentation Engineering ii


After Initializing Truffle:

4.3 Interacting with the deployed smart contract:

In truffle console
truffle(ganache)> const hello = await Hello.deployed()
truffle(ganache)> const address = await hello.address
truffle(ganache)> address
'0x46C00D73bF785000B3c3F93569E84415AB2381f2'

truffle(ganache)> const message = await hello.message()


truffle(ganache)> message

Electronics and Instrumentation Engineering ii


truffle(ganache)> await hello.setMessage('Hi there!')
truffle(ganache)> await hello.message()

4.4 Testing smart contracts


const { assert } = require("chai")

const Hello = artifacts.require("./Hello.sol")

require("chai")
.use(require("chai-as-promised"))
.should()

contract('Hello', ([contractOwner, secondAddress, thirdAddress]) => {


let hello

// this would attach the deployed smart contract and its methods
// to the `truffleTutorial` variable before all other tests are run
before(async () => {
hello = await Hello.deployed()
})

// check if deployment goes smooth


describe('deployment', () => {
// check if the smart contract is deployed
// by checking the address of the smart contract

Electronics and Instrumentation Engineering ii


it('deploys successfully', async () => {
const address = await hello.address

assert.notEqual(address, '')
assert.notEqual(address, undefined)
assert.notEqual(address, null)
assert.notEqual(address, 0x0)
})

// check if the message is stored on deployment as expected


it('has a message', async () => {
const message = await hello.message()
assert.equal(message, 'Hello World!')
})
})

describe('message', () => {
// check if owner can set new message, check if setMessage works
it('contract owner sets a message', async () => {
// set new message
await hello.setMessage('Hi there!', { from: contractOwner })
// `from` helps us identify by any address in the test

// check new message


const message = await hello.message()
assert.equal(message, 'Hi there!')
})

// make sure only owner can setMessage and no one else


it('address that is not the owner fails to set a message', async () => {
await hello.setMessage('Hi there!', { from: secondAddress })
.should.be.rejected
// this tells Chai that the test should pass if the setMessage function fails.

await hello.setMessage('Hi there!', { from: thirdAddress })


.should.be.rejected
})
})
})
We Get:
Using network 'ganache'.

Contract: Hello
deployment
✓ deploys successfully
✓ has a message (236ms)
message
✓ contract owner sets a message (165ms)
✓ address that is not the owner fails to set a message (250ms)

4 passing (735ms)

Electronics and Instrumentation Engineering ii


Chapter 5: Conclusion
As the blooming topic of the recent days web3. Ganache
helps us to provide an Easy way to implement it.

Developing dApps can be quite the hassle, which is why


it’s beneficial to use platforms that expedite the
development process. One way in which development can
become easier is by setting up a local dev chain where we
can test our dApps for free and with high efficiency. One
platform that offers just that is Ganache.

The advantages of time with Ganache are clearly evident in


the flexibility for faster uploading of your smart contract on
the local blockchain network

Electronics and Instrumentation Engineering ii

You might also like