[ad_1]
Transaction logs
One last thing before you deploy.
I want to modify the smart contract so that you can see transaction activity on Etherscan (a block explorer) later when you deposit and withdraw.
In Solidity, you can use Events to post transaction logs to the blockchain.
Now the contract will look like this:
pragma solidity ^0.8.4;contract owned {
bool public paused;
address owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner, "Only contract owner can call this function");
_;
}
}
contract pausable is owned {
function setPaused(bool _paused) public onlyOwner {
paused = _paused;
}
}
contract Faucet is pausable {
// Events
event Withdrawal(address indexed to, uint amount);
event Deposit(address indexed from, uint amount);
function withdraw(uint withdraw_amount) public {
require(paused == false, "Function paused");
require(withdraw_amount <= 0.1 ether, "Withdrawals are limited to 0.1 ether");
require(address(this).balance >= withdraw_amount, "Insufficient balance in faucet");
payable(msg.sender).transfer(withdraw_amount);
// event data -> transaction logs
emit Withdrawal(msg.sender, withdraw_amount);
}
function deposit() public payable {
// event data -> transaction logs
emit Deposit(msg.sender,msg.value);
}
}
Don’t forget to compile the updated contract.
npx hardhat compile
[ad_2]
Source link