0% found this document useful (0 votes)
10 views9 pages

BCLab - Experiment No2

Uploaded by

cleverchatelet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

BCLab - Experiment No2

Uploaded by

cleverchatelet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Don Bosco Institute of Technology, Kulra(W)

Department of Computer Engineering


CSDL7022: Blockchain Lab 2023-24

Experiment No. 02

Experiment Title Creating Smart Contract using Solidity and Remix IDE.

Task1 - Study Remix IDE and solidity for blockchain


Programming

Deliverables: One Page report on Remix IDE and solidity

Task2 - Study how to define and use variables and functions in smart
contracts.

Task3 - Creating Smart Contract using Solidity and Remix IDE.

a) Smart contract for simple addition of two numbers

b) Write a program in solidity to check whether a number is prime


or not.
c) Write a program to implement multilevel inheritance

Student Name Gavin Pereira

47
Roll No.

1) Students will be able to understand Remix IDE.


Objectives: 2) Students will be able to write programs in solidity. 3)
Students will be able to implement smart contracts.

Course Outcome: CSDL7022.4: Design smart contract using solidity

Theory
/Algorithm: Task1 - Study Remix IDE and solidity for blockchain
Programming

Remix IDE and Solidity: A Brief Overview

Remix IDE:

Remix IDE is an integrated development environment IDE)


for writing, testing, and deploying Solidity smart contracts on
the Ethereum blockchain. It is web-based and offers a
comprehensive set of tools that make it easier for developers
to work with blockchain technologies.
Key Features of Remix IDE:

1. Editor: Remix provides a powerful code editor with syntax


highlighting and auto-completion features tailored for Solidity
smart contract development.

2. Compiler: It includes a built-in Solidity compiler that


allows developers to compile their smart contracts directly
within the IDE. Compilation helps to check for syntax errors
and ensures contracts are compatible with the Ethereum
Virtual Machine (EVM).

3. Debugger: Remix offers a debugger tool that assists


developers in debugging their smart contracts step-by-step.
This is crucial for identifying and fixing logical errors and
verifying contract behavior.

4. Testing: Developers can write and execute unit tests for


their smart contracts using Remix. This ensures that contracts
behave as expected under different conditions and scenarios.

5. Deployment: Remix allows for easy deployment of smart


contracts onto Ethereum test networks (like Ropsten, Rinkeby)
and the main Ethereum network. It simplifies the process of
interacting with deployed contracts for testing and production
purposes.

Solidity:

Solidity is a statically-typed programming language designed


specifically for writing smart contracts on Ethereum and other
EVM-compatible blockchains. It draws syntax inspiration
from JavaScript, Python, and C++, making it accessible to
developers familiar with these languages.

Key Features of Solidity:

1. Smart Contracts: Solidity enables developers to define


smart contracts that can hold and manage digital assets,
execute functions based on predefined conditions, and interact
with other contracts and users on the blockchain.

2. Security: It emphasizes security best practices such as


visibility specifiers (public, private, internal), state variables,
and function modifiers to protect against vulnerabilities like
reentrancy and unauthorized access.
3. Ecosystem: Solidity is supported by a robust developer
community and has extensive documentation, libraries, and
frameworks (like OpenZeppelin) that facilitate rapid and
secure smart contract development.

4. Integration: Solidity integrates seamlessly with Remix


IDE, allowing developers to compile, debug, test, and deploy
contracts directly from the IDE environment.

Conclusion:

Remix IDE and Solidity are indispensable tools for developers


entering the blockchain space. They provide a user-friendly
environment and a powerful language, respectively, to create
secure and efficient smart contracts. Mastery of these tools
enables developers to participate in the decentralized finance
(DeFi), non-fungible token (NFT), and broader blockchain
ecosystem with confidence.

Program Code: Task2 - Study how to define and use variables and functions in smart

contracts.

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

contract Addition {

uint private val; // Private variable to store the value

// Function to set the value of 'val'

function set(uint a) public {

val = a;

// Function to get the current value of 'val'

function get() public view returns (uint) {


return val;

Task3 - Creating Smart Contract using Solidity and Remix IDE.

a) Smart contract for simple addition of two numbers

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract Addition {
uint private val; // Private variable to store the value

// Function to set the value of 'val'


function set(uint a) public {
val = a;
}

// Function to get the current value of 'val'


function get() public view returns (uint) {
return val;
}

// Function to add two numbers and return the result


function add(uint a, uint b) public pure returns (uint) {
return a + b;
}
}

b) Write a program in solidity to check whether a number is prime or not.

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract PrimeChecker {
// Function to check if a number is prime
function isPrime(uint number) public pure returns (bool) {
if (number <= 1) {
return false;
}
if (number == 2) {
return true;
}
if (number % 2 == 0) {
return false;
}
for (uint i = 3; i * i <= number; i += 2) {
if (number % i == 0) {
return false;
}
}
return true;
}
}

c) Write a program to implement multi level inheritance


// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

// Parent contract A
contract A {
uint public a;

constructor(uint _a) {
a = _a;
}
}

// Intermediate contract B inherits from A


contract B is A {
uint public b;

constructor(uint _a, uint _b) A(_a) {


b = _b;
}
}

// Final contract C inherits from B


contract C is B {
uint public c;

constructor(uint _a, uint _b, uint _c) B(_a, _b) {


c = _c;
}
}

Output of the
Program:
Outcome of the The outcomes of the experiments involve creating and testing three succinct
Experiment: Solidity smart contracts using Remix IDE. The first contract performs simple
addition of two numbers, demonstrating basic arithmetic operations in
Ethereum smart contracts. The second contract checks whether a given
number is prime, showcasing conditional logic and iteration within Solidity.
Lastly, the third contract implements multi-level inheritance, illustrating
hierarchical structuring of contracts to inherit functionality and state variables
across different levels. These exercises not only familiarize with fundamental
Solidity syntax and features but also demonstrate practical application of
blockchain programming concepts using Remix IDE's development
environment.

References: Google, Elearn


Course in-charge-Mayura Gavhane

You might also like