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

Blockchain Technology - 3

Sppu BE BT assignment 3

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)
15 views3 pages

Blockchain Technology - 3

Sppu BE BT assignment 3

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 03

Harshal Vijay Umale


Roll Number:0052
BE Comp

Title: : Solidity Smart Contract

Date of Completion:

Problem Definition:
Write a smart contract on a test network, for Bank account of a customer for
following operations:
• Deposit money
• Withdraw Money
• Show balance

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. Functions
Definition: Functions are reusable blocks of code that perform specific tasks. They
allow developers to encapsulate logic, making contracts more modular and
manageable.
Visibility Modifiers:
public: Accessible from anywhere, including externally and internally.
private: Accessible only within the contract itself.
internal: Accessible within the contract and derived contracts.
external: Accessible only from outside the contract.
Eg:
function add(uint256 a, uint256 b) public pure returns (uint256) {
return a + b;
}

2. Mappings
Definition: Mappings are key-value stores that allow for the association of unique
keys to specific values. They are similar to hash tables or dictionaries in other
programming languages.

· Mappings do not have a length and cannot be iterated over.


· If a key does not exist, it returns the default value of the value type.
Eg:
mapping(address => uint256) public balances;

3. Addresses
Definition: The address type is used to store Ethereum addresses. Addresses can
represent user accounts or smart contracts.

Eg:
address owner;

function setOwner(address _owner) public {


owner = _owner;
}

4. Basic Data Types


Solidity supports several basic data types, which can be broadly categorized into:

Value Types: These hold their value directly.

uint: Unsigned integers of various sizes (e.g., uint8, uint256).


int: Signed integers (e.g., int8, int256).
bool: Boolean type (true or false).
address: Holds Ethereum addresses.
fixed-size byte arrays: bytes1, bytes2, ..., bytes32.
enum: User-defined type that consists of a set of named values.

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

struct Person {
string name;
uint age;
}

Code:

Conclusion:
Thus, we have successfully understood how to write the solidity code for creating a
smart contract simulating an Ether based bank transaction system.

You might also like