BCLab - Experiment No2
BCLab - Experiment No2
Experiment No. 02
Experiment Title Creating Smart Contract using Solidity and Remix IDE.
Task2 - Study how to define and use variables and functions in smart
contracts.
47
Roll No.
Theory
/Algorithm: Task1 - Study Remix IDE and solidity for blockchain
Programming
Remix IDE:
Solidity:
Conclusion:
Program Code: Task2 - Study how to define and use variables and functions in smart
contracts.
// SPDX-License-Identifier: GPL-3.0
contract Addition {
val = a;
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Addition {
uint private val; // Private variable to store the value
// 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;
}
}
// Parent contract A
contract A {
uint public a;
constructor(uint _a) {
a = _a;
}
}
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.