DEPARTMENT OF COMPUTER ENGINEERING
CSDL7022 Blockchain Lab
Seventh Semester, 2024-2025 (Odd Semester)
Name of Student : GUPTA
AYUSH Roll No. 21
Division :A
Batch : A1
Day / Session : THURSDAY
/ Afternoon Venue : 310
Experiment No. 05
Title of Experiment : Embedding wallet and transaction using Solidity
Date of Conduction : 03/09/2025
Date of Submission : 10/09/2025
Particulars Max. Marks
Marks Obtained
Preparedness and Efforts(PE) 3
Knowledge of tools(KT) 3
Debugging and results(DR) 3
Documentation(DN) 3
Punctuality & Lab Ethics(PL) 3
Total 15
Grades – Meet Expectations (3 Marks), Moderate Expectations (2 Marks), Below Expectations (1 Mark)
Checked and Verified by
Name of Faculty : Pravin Jangid
Signature :
Date :
Experiment No 5:
Title: Embedding wallet and transaction using Solidity
Objective:
The primary objective of this experiment is to design, develop, and deploy a smart
contract using Solidity that functions as a basic Ethereum wallet. This contract will
allow multiple users to deposit Ether into it, and provide the contract owner with the
ability to securely transfer Ether to other Ethereum addresses.
Theory:
Metamask:
MetaMask is a popular cryptocurrency wallet known for its ease of use, availability on
both desktops and mobile devices, the ability to buy, send, and receive cryptocurrency
from within the wallet, and collect non-fungible tokens (NFTs) across two
blockchains. While experienced crypto users will appreciate the simplicity and fast
transactions, those new in the space are at a higher risk of losing their tokens from lost
secret phrases, malicious websites, and other cryptocurrency scams.
Easy download and setup across devices.
No signup process involving personally identifiable information
Create multiple wallets inside one app
Supports all ERC-20 tokens, NFTs, and multiple blockchains
1. Ethereum Wallets:
An Ethereum wallet is an application that stores users' private keys and allows
them to send and receive Ether or tokens. In blockchain systems, wallets are
usually off-chain software or hardware components. However, smart contracts
themselves can act as wallets by holding Ether and defining rules for transferring
those funds.
2. Smart Contract as a Wallet:
A smart contract wallet is a contract deployed on the blockchain that can hold
and manage Ether under predefined rules. Unlike regular wallets, the control
logic is programmed and immutable once deployed. This means transactions
can be automated and governed by code rather than human intervention alone.
3. Ether Deposits:
Users can send Ether to the contract by invoking a payable function (like
deposit()) which accepts Ether. The Ether is credited to the contract’s balance
(i.e., the amount of Ether stored at the contract's address).
4. Controlled Ether Transfers:
To ensure security, only authorized parties (e.g., contract owner) should be able
to move Ether out of the contract. This is enforced through access control
modifiers (onlyOwner). Attempting to transfer more Ether than the contract
holds results in a failed transaction.
5. Events for Transparency:
Events (Deposit and Transfer) are emitted during deposits and withdrawals.
Events are stored on the blockchain's transaction logs and can be indexed and
queried by off-chain services (like block explorers or decentralized apps),
providing transparency and traceability.
6. Security Considerations:
i) Access Control: Restrict sensitive functions (like sending Ether) to
the owner
ii) .Balance Checks: Always verify contract balance before transferring
to avoid underflows.
iii) Reentrancy Attacks: The contract uses .transfer() which forwards
limited gas, reducing reentrancy risks. More complex contracts should
consider ReentrancyGuard.
Goerli Test Net:
Goerli is an Ethereum test network that allows for blockchain development testing
before deployment on Mainnet, the main Ethereum network. The Proof-of-Authority
test network was established in March 2019. It uses the Clique consensus mechanism
and was originally proposed by Chainsafe and Afri Schoedon.
Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
contract DecentralizedBank
{ mapping(address => uint) public
balances; address public owner;
event Deposit(address indexed user, uint amount);
event Withdrawal(address indexed user, uint amount);
constructor() {
owner = msg.sender;
}
// Deposit Ether into the bank
function deposit() external payable {
require(msg.value > 0, "Must deposit some Ether");
balances[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
// Withdraw specified amount of Ether from the bank
function withdraw(uint _amount) external {
require(balances[msg.sender] >= _amount, "Insufficient balance");
balances[msg.sender] -= _amount;
payable(msg.sender).transfer(_amount);
emit Withdrawal(msg.sender, _amount);
}
// Check contract balance
function getBankBalance() external view returns (uint)
{ return address(this).balance;
}
}
Output:
\
Conclusion: This experiment successfully demonstrated how to create and interact
with a simple Decentralized Bank using Solidity. Users were able to securely deposit
and withdraw Ether while maintaining individual balances on the blockchain,
showcasing fundamental concepts of smart contract-based financial applications.