0% found this document useful (0 votes)
14 views45 pages

Exp1 Merged

Uploaded by

Dev Khatanhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views45 pages

Exp1 Merged

Uploaded by

Dev Khatanhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Code:

Output:
Code:

Output:
Code:

// SPDX-License-Identifier: MIT

pragma solidity >= 0.8.2 <0.9.0;

contract TransactionContract {

event TransactionMade(address indexed from, address indexed to, uint amount);

struct Transaction {

address from;

address to;

uint amount;

uint timestamp;

Transaction[] public transactions;

mapping(address => uint) public balances;

function createTransaction(address payable _to) public payable {

require(msg.sender.balance >= msg.value, "Insufficient balance");

transactions.push(Transaction(msg.sender, _to, msg.value, block.timestamp));

balances[msg.sender] -= msg.value;

balances[_to] += msg.value;

emit TransactionMade(msg.sender, _to, msg.value);

_to.transfer(msg.value);

function getAllTransactions() public view returns (Transaction[] memory) {

return transactions;

}
function getBalance(address _addr) public view returns (uint) {

return balances[_addr];

Output:
Code:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract EmbeddedWallet {

event Deposit(address indexed user, uint amount);

event Withdrawal(address indexed user, uint amount);

event Transfer(address indexed from, address indexed to, uint amount);

mapping(address => uint) public balances;

modifier hasEnoughFunds(uint amount) {

require(balances[msg.sender] >= amount, "Insufficient funds");

_;

function deposit() public payable {

require(msg.value > 0, "Deposit must be greater than 0");

balances[msg.sender] += msg.value;

emit Deposit(msg.sender, msg.value);

function withdraw(uint amount) public hasEnoughFunds(amount) {

balances[msg.sender] -= amount;

payable(msg.sender).transfer(amount);

emit Withdrawal(msg.sender, amount);

function transfer(address to, uint amount) public hasEnoughFunds(amount) {

require(to != address(0), "Invalid recipient address");


require(to != msg.sender, "Cannot transfer to yourself");

balances[msg.sender] -= amount;

balances[to] += amount;

emit Transfer(msg.sender, to, amount);

function getBalance(address _addr) public view returns (uint) {

return balances[_addr];

Output:

Deposit function -
Transfer function -
OUTPUT:
Output:

You might also like