Ether Wallet
Ethereum wallets are applications that let you interact with your Ethereum account. Think of it like an internet banking app β without the bank. Your wallet lets you read your balance, send transactions and connect to applications.
The owner's address is listed first in the contract.
address payable public owner;
The address has the designation payable
so that ether can be sent to it.
The owner variable in the constructor is set to msg.sender
, or the deployer of the contract, upon initialization.
constructor() {
owner = payable(msg.sender);
}
We now have two unique functions called "receive" and "fallback" that allow the contract to accept plain ether with or without a calldata. For more information on these functions, read on.
receive() external payable {}
fallback() external payable {}
Following this, we require a function to withdraw our ether to the address of the owner; the withdraw
function aids us in doing this. It has a require
statement that makes that the owner, whom we initialised in the constructor, is the one calling the method. We transfer ether from the smart contract to the msg.sender
if that criterion is satisfied.
function withdraw(uint _amount) external {
require(msg.sender == owner, "caller is not owner");
payable(msg.sender).transfer(_amount);
}
Finally, we create a new function named getBalance
, which is a view function, meaning that anyone can call it to retrieve the smart contract's balance without affecting the blockchain's current state.
function getBalance() external view returns (uint) {
return address(this).balance;
}
For Entire Code -
web3astronaut / Smart-Contracts
A Collection of smart contracts to aid you with your web 3 projects.
Collection of deployable smart contracts for Ethereum-based chains to hasten development
π About Smart Contracts
The sole venue for smart contract programmers to display their concepts and work. To get you started on your web3 adventure, this repository will offer a selection of smart contracts ranging in difficulty from beginner to expert.
πΊοΈ How to Contribute?
- Check out the current issues or start a new one!
- Create a branch for each problem you are working on, fork the repository, and then commit your changes.
- Create a Pull Request (
PR
), which will be promptly reviewed and given suggestions for improvements by the community. - Additionally, supply the solidity source files and a descriptive readme on how the smart contract works.
π How to make a Pull Request?
-
Make a fork of the Smart-Contracts repository first. In the top right corner, click the fork icon.
-
Clone your new fork of theβ¦
Top comments (0)