Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

DEPARTMENT OF COMPUTER ENGINEERING

CSDL7022 Blockchain Lab

Seventh Semester, 2022-2023 (Odd Semester)

Name of Student :

Roll No. :

Division :C

Batch :

Day / Session :

Venue :

Experiment No. :2

Title of Experiment :Creating Smart Contract using Solidity and Remix IDE.

Date of Conduction :

Date of Submission :

Particulars Max. Marks


Marks Obtained
Preparedness and Efforts(PE) 3

Knowledge of tools(KT) 3

Debugging and results(DR) 3

Documentation(DN) 3

Punctuality & Lab Ethics(PL) 3

Total 15

Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations (1 Mark)

Checked and Verified by

Name of Faculty : Pravin Jangid

Signature :

Date :

Experiment No 2:

Aim : Creating Smart Contract using Solidity and Remix IDE .


Smart contract definition

Smart contracts are simply programs stored on a blockchain that run when
predetermined conditions are met. They typically are used to automate the execution of
an agreement so that all participants can be immediately certain of the outcome, without
any intermediary’s involvement or time loss. They can also automate a workflow,
triggering the next action when conditions are met.

Working of smart contracts

Smart contracts work by following simple “if/when…then…” statements that are written
into code on a blockchain. A network of computers executes the actions when
predetermined conditions have been met and verified. These actions could include
releasing funds to the appropriate parties, registering a vehicle, sending notifications, or
issuing a ticket. The blockchain is then updated when the transaction is completed. That
means the transaction cannot be changed, and only parties who have been granted
permission can see the results.

Within a smart contract, there can be as many stipulations as needed to satisfy the
participants that the task will be completed satisfactorily. To establish the terms,
participants must determine how transactions and their data are represented on the
blockchain, agree on the “if/when...then…” rules that govern those transactions, explore
all possible exceptions, and define a framework for resolving disputes.

Then the smart contract can be programmed by a developer – although increasingly,


organizations that use blockchain for business provide templates, web interfaces, and
other online tools to simplify structuring smart contracts.

Benefits of smart contracts

Speed, efficiency and accuracy


Once a condition is met, the contract is executed immediately. Because smart contracts
are digital and automated, there’s no paperwork to process and no time spent
reconciling errors that often result from manually filling in documents.

Trust and transparency


Because there’s no third party involved, and because encrypted records of transactions
are shared across participants, there’s no need to question whether information has
been altered for personal benefit.
Security
Blockchain transaction records are encrypted, which makes them very hard to hack.
Moreover, because each record is connected to the previous and subsequent records
on a distributed ledger, hackers would have to alter the entire chain to change a single
record.

Savings
Smart contracts remove the need for intermediaries to handle transactions and, by
extension, their associated time delays and fees.

Applications of smart contracts


1. Safeguarding the efficacy of medications
2. Increasing trust in retailer-supplier relationships
3. Making international trade faster and more efficient

Code :-
// SPDX-
License-
Identifier:
MIT
pragma solidity ^0.8.11;

contract Election {
struct Candidate {
uint id;
string name;
uint voteCount;
}
bool goingon = true;
mapping(address => bool) public voters;
mapping(uint => Candidate) public candidates;
uint public candidatesCount;

event votedEvent (
uint indexed _candidateId
);

constructor () {
addCandidate("Bob");
addCandidate("Allice");

function addCandidate (string memory _name) private {


candidatesCount ++;
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);
}

function end () public {


goingon = false;
}

function vote (uint _candidateId) public {


require(!voters[msg.sender],"Already voted");

require(_candidateId > 0 && _candidateId <= candidatesCount,"Invalid


candidate");

require(goingon,"Election ended");

voters[msg.sender] = true;

candidates[_candidateId].voteCount ++;

emit votedEvent(_candidateId);
}
}

Output:-
Conclusion: We have Created an Smart Contract using Solidity and
Remix IDE.

You might also like