OnlyOwnerWithdrawal Smart Contract
This is a Solidity smart contract that only allows withdrawals by a specific address (0x123
). It is designed to be used as a template for creating smart contracts that have restricted access to their functions.
Usage
To use this smart contract, you will need to deploy it to the Ethereum network using a tool like Remix IDE. You can then interact with the contract by calling its functions using a compatible Ethereum wallet, such as MetaMask.
Constructor
The OnlyOwnerWithdrawal
constructor sets the owner
address to the address that deploys the contract. This is done by setting the owner
variable to msg.sender
.
Withdraw function
The withdraw
function is used to transfer all the funds in the contract to the owner's address. It includes a require
statement that checks whether the caller of the function is 0x123
, and reverts the transaction if the condition is not met.
Receive function
The receive
function is included to enable the contract to receive funds. When someone sends ether to the contract's address, the receive
function is called automatically.
Deployment
To deploy this smart contract, follow these steps:
- Open Remix IDE and create a new Solidity file.
- Copy and paste the code from this repository into the file.
- Compile the code by clicking the
Compile
button in the Remix IDE. - Click the
Deploy & Run Transactions
tab in the Remix IDE. - Select the Ethereum network you want to deploy the contract to from the dropdown menu.
- Make sure the
OnlyOwnerWithdrawal
contract is selected in the Contract dropdown. - Click the
Deploy
button. - Confirm the transaction in your Ethereum wallet.
Testing
To test this smart contract, follow these steps:
- Deploy the contract to a test network, such as Rinkeby or Kovan.
- Send ether to the contract's address.
- Call the
withdraw
function using an Ethereum wallet that is not associated with the0x123
address. - Confirm that the transaction reverts.
- Call the
withdraw
function using an Ethereum wallet that is associated with the0x123
address. - Confirm that the funds are transferred to the owner's address.
License
This smart contract is licensed under the MIT License. See LICENSE for more information.