This repository contains a Solidity smart contract called Staker
. The Staker
contract allows users to stake Ether and trigger an external contract's function once a specified threshold is reached. The contract also includes a deadline, after which users can withdraw their stake if the threshold has not been met.
- Stake Ether and track individual balances
- Set a threshold and deadline for triggering the external contract
- Execute the external contract's function if the deadline has passed and the threshold is met
- Withdraw the user's balance if the deadline has passed and the threshold has not been met
- Calculate the time left before the deadline
- Deploy the
ExampleExternalContract
and note its address. - Deploy the
Staker
contract, passing the address of theExampleExternalContract
as a constructor argument. - Users can stake Ether by calling the
stake()
function or sending Ether directly to the contract. - After the deadline has passed, if the threshold is met, anyone can call the
execute()
function to trigger the external contract's function. - If the deadline has passed and the threshold has not been met, users can call the
withdraw()
function to retrieve their staked Ether.
// Deploy the ExampleExternalContract
ExampleExternalContract exampleExternalContract = new ExampleExternalContract();
// Deploy the Staker contract with the address of the ExampleExternalContract
Staker staker = new Staker(address(exampleExternalContract));
// Stake Ether
staker.stake{value: 1 ether}();
// Execute the external contract's function after the deadline and if the threshold is met
staker.execute();
// Withdraw Ether if the deadline has passed and the threshold has not been met
staker.withdraw();