[go: up one dir, main page]

0% found this document useful (0 votes)
21 views3 pages

Blockchain Technology - 4

Sppu BE BT assignment 4

Uploaded by

21110052
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)
21 views3 pages

Blockchain Technology - 4

Sppu BE BT assignment 4

Uploaded by

21110052
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/ 3

Blockchain Technology- Assignment 04

Harshal Vijay Umale


Roll Number:0052
BE Comp

Title: : Solidity Smart Contract

Date of Completion:

Problem Definition:
Write a program in solidity to create Student data. Use the following constructs:
• Structures
• Arrays
• Fallback
Deploy this as smart contract on Ethereum and Observe the transaction fee and Gas
values.

Theory:

Solidity:

Solidity is a statically typed programming language designed for developing smart


contracts that run on the Ethereum blockchain and other Ethereum-compatible
networks. It was influenced by languages like JavaScript, C++, and Python, making it
accessible to developers familiar with these languages.

Key Features:

Statically Typed: Solidity requires variable types to be defined at compile time, which
helps catch errors early in the development process.

Object-Oriented: The language supports object-oriented programming principles,


allowing developers to create complex data structures and reuse code through
inheritance and libraries.

Smart Contract Focused: Solidity is specifically designed for writing smart contracts,
which are self-executing contracts with the terms directly written into code. These
contracts facilitate, verify, or enforce the negotiation or performance of a contract.

Ethereum Virtual Machine (EVM) Compatibility: Solidity code is compiled into


bytecode that runs on the EVM, ensuring that contracts can be executed across the
Ethereum network.
Inheritance and Interfaces: Solidity supports multiple inheritance, enabling developers
to create sophisticated contract architectures. It also allows for the creation of
interfaces, which facilitate interactions between contracts.

Constructs:

1. Structures
Definition: Structures (or structs) are custom data types that group related variables
under a single name. They allow developers to create complex data types by
combining different value types.
Eg:
struct StructName {
dataType1 fieldName1;
dataType2 fieldName2;
// ... more fields
}

2. Arrays
Definition: Arrays are collections of elements of the same data type. Solidity supports
both fixed-size and dynamic arrays.
Types:
Fixed-size arrays: The size is defined at compile time.
Dynamic arrays: The size can change at runtime.

Eg:
dataType[] public dynamicArray; // Dynamic array
dataType[5] public fixedArray; // Fixed-size array

3. Fallback Function
Definition: The fallback function is a special function that does not have a name and
does not take any arguments. It is executed when a contract receives Ether and no
other function matches the call.
Characteristics:
Cannot have a return value.
Can be used to handle plain Ether transfers.
Only one fallback function is allowed per contract.

Eg:
fallback() external payable {
// Code to execute when Ether is sent to the contract without matching function
}

4. Receive Function
Definition: The receive function is a specific type of fallback function that is called
when a contract receives Ether and the call data is empty. It allows contracts to react
specifically to Ether transfers.
Characteristics:
Can only be defined once in a contract.
Must be marked as payable.

Eg:
receive() external payable {
// Code to execute when Ether is sent directly to the contract
}

5. Events
Definition: Events allow contracts to log information on the blockchain, which can be
listened to by external applications. Events provide a way to communicate that
something has happened in the contract.
Usage: They are particularly useful for tracking changes in contract state or for
notifying clients of important actions.
Eg:
event EventName(dataType1 indexed param1, dataType2 param2);

Code:

Conclusion:
Thus, we have successfully understood how to write the solidity code for creating a
smart contract simulating student database.

You might also like