Professional Documents
Culture Documents
Practical No 4
Practical No 4
Aim: 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.
StudentData.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract StudentData {
struct Student {
uint256 id;
string name;
uint256 age;
}
fallback() external {
revert("Fallback function called. This contract does not accept Ether.");
}
function getStudent(uint256 _index) public view returns (uint256, string memory, uint256)
{
require(_index < students.length, "Index out of bounds");
Student storage s = students[_index];
return (s.id, s.name, s.age);
}