Blockchain Technology - 3
Blockchain Technology - 3
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:
Key Features:
Statically Typed: Solidity requires variable types to be defined at compile time, which
helps catch errors early in the development process.
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.
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.
3. Addresses
Definition: The address type is used to store Ethereum addresses. Addresses can
represent user accounts or smart contracts.
Eg:
address owner;
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.