The Force Sender project explores the concept of forcibly sending native tokens to smart contracts. Unlike externally owned accounts (EOAs), smart contracts require a receive function or a fallback payable to accept native tokens.
This project demonstrates how to use the selfdestruct mechanism to compel the transfer of native tokens, even if the recipient contract doesn't implement a special function like receive or fallback.
The primary goal of the Force Sender project is to:
- Highlight Selfdestruct for Forced Native Token Transfer: Shed light on the utilization of the
selfdestructmechanism to forcefully transfer native tokens to contracts. By leveragingselfdestruct, native tokens accumulated within one contract can be seamlessly sent to an address without invoking a specific function, even if the recipient is a smart contract.
-
Contract Creation using the
newKeyword: Unlike previous projects that employed directCREATEorCREATE2opcodes with bytecode like Factory and Minimal-Proxy, this project uses thenewkeyword to create a new contract. This approach leverages a pre-defined contract template to streamline deployment. -
Usage of
selfdestruct: Whileselfdestructserves the purpose in this project, it is important to approach its usage with caution. This mechanism should be employed thoughtfully, and researchers must perform due diligence before utilizing it, especially considering ongoing discussions in the Ethereum Improvement Proposal (EIP) space about its deprecation. -
Documented with Natspec: The project's functions and overall functionality are documented using
natspec, providing clear insights into each function's purpose and usage. -
Unit Tests with ethers.js: The project incorporates unit tests written with
ethers.jsto verify the functionality of the implemented contracts.
Note: The Force Sender project is educational and intended to explore the concept of forcibly transferring native tokens to contracts. It is not suitable for deployment in a production environment.
To get started with the Force Sender project, clone the repository and install its dependencies:
$ git clone https://github.com/0xAdnanH/Force-Sender.git
$ cd ./Force-Sender
$ npm installTo Compile the contract run:
$ npx hardhat compileTo run the unit tests:
$ npx hardhat test