A Solidity smart contract for the transfer of Ethereum with various conditions.
- Solidity Version: 0.7.0
- License: MIT
- The contract is for the transfer of a certain number of Ethereum with a minimum of 0.001 Ether and a maximum of 10 Ether.
- The contract has an ether payer and an ether receiver.
- The payer and receiver must agree on the number of Ether for the transaction, and this agreement is done by paying a fee of 0.000001 Ether as fee #1 on both sides.
- Ethers will not be transferred until both parties have agreed, and a signature in the contract for the agreement is obtained by deducting the cost of 0.000001 Ether as fee #2.
- Fee No. 1 and Fee No. 2 are deposited into the account of the contract owner.
- After the transaction is completed, the contract returns to its initial state and is ready for a new transaction.
- The contract should be implemented in version 7 of Solidity.
- Security measures have been implemented in the contract.
- Special attention has been given to numbers and calculations.
- The contract owner is responsible for initiating the transfer and withdrawing the fees.
- The payer and receiver must call the
agreeTransfer
function, paying the fee of 0.000001 Ether each, to indicate their agreement. - Once both parties have agreed, the contract transfers the agreed amount of Ether to the receiver and the fees to the contract owner.
- The contract also includes a
getContractBalance
function to check the contract's balance and awithdrawFees
function for the contract owner to withdraw the accumulated fees.
To initiate a transfer, call the initiateTransfer
function and send the desired amount of Ether as the value. The transfer amount must be within the specified range.
function initiateTransfer() external payable
Both the payer and receiver must agree on the transfer by calling the agreeTransfer function and paying the fee #1 (0.000001 Ether). The function checks the caller's role and ensures that each party can only agree once.
function agreeTransfer() external payable
If both the payer and receiver have agreed, the transferEther
function is called internally to transfer the agreed amount of Ether to the receiver and the fees to the contract owner.
The getContractBalance
function allows anyone to check the balance of the contract.
function getContractBalance() public view returns (uint256)
The contract owner can withdraw the accumulated fees by calling the withdrawFees
function.
function withdrawFees() external onlyOwner
The contract implements a modifier onlyOwner
to restrict access to certain functions only to the contract owner.
Input validation is performed to ensure the transfer amount is within the specified range and the fee amounts are correct.
The contract checks for sufficient balance before transferring Ether or fees.
The contract utilizes the payable
modifier for receiving Ether.
This contract assumes a trusted environment and does not implement sophisticated security measures such as access control or input sanitization. It is essential to thoroughly review and test the contract before deploying it to the Ethereum network.
To deploy and test the EtherTransferContract, follow these steps:
Clone this repository:
git clone https://github.com/hajihashemabad/EtherTransferContract.git
-
Install Truffle and set up a development environment.
-
Create a new Solidity file and copy the contract code.
-
Compile the contract using Truffle's compiler.
-
Configure the deployment network in the Truffle configuration file (
truffle-config.js
ortruffle.js
). -
Deploy the contract to the desired network using the Truffle migration scripts.
-
Write test cases using a testing framework like Truffle Test.
-
Run the test cases to verify the contract's functionality.
-
Make sure to test different scenarios, including edge cases and invalid inputs, to ensure the contract behaves as expected.
This project is licensed under the MIT License.
I welcome contributions to the EtherTransferContract project! If you'd like to contribute, please fork the repository and create a new branch for your changes. Once you've made your changes, submit a pull request and I'll review it as soon as possible.
Contributions are welcome! If you want to contribute to this project, follow these steps:
- Fork this repository.
- Create a new branch:
git checkout -b my-new-branch
. - Make your changes and commit them:
git commit -am 'Add some feature'
. - Push to the branch:
git push origin my-new-branch
. - Submit a pull request.
Please ensure that your code follows the repository's coding conventions and passes any existing tests.
If you have any questions or comments about EtherTransferContract Smart Contract, feel free to reach out to me at Email.