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.
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.
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.
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.
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.
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
Compilebutton in the Remix IDE. - Click the
Deploy & Run Transactionstab in the Remix IDE. - Select the Ethereum network you want to deploy the contract to from the dropdown menu.
- Make sure the
OnlyOwnerWithdrawalcontract is selected in the Contract dropdown. - Click the
Deploybutton. - Confirm the transaction in your Ethereum wallet.
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
withdrawfunction using an Ethereum wallet that is not associated with the0x123address. - Confirm that the transaction reverts.
- Call the
withdrawfunction using an Ethereum wallet that is associated with the0x123address. - Confirm that the funds are transferred to the owner's address.
This smart contract is licensed under the MIT License. See LICENSE for more information.