1

Is there any way to send an amount of eth to a smart contract address setting a delay time before the sender address could redeem?

  • Add a modifier to the payment function that requires the blocknumber to be greater than a certain number in the future? – Samuel Dare Jul 29 '19 at 21:31
0

OpenZeppelin has a TokenTimelock contract and you could use a similar idea for Ether. https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#TokenTimelock

0

The code below allows several users to lock ether in a smart contract. Each subject can withdraw the ether that he/she deposited after a certain amount of time (in this example 1 day).

pragma solidity ^0.5.1;

contract timeLock {

    uint256 lockTime = 1 days;

    struct locked{
        uint256 expire;
        uint256 amount;
    }

    mapping(address => locked) users;

    function lockEther() public payable {
        require(msg.value>0);
        locked storage userInfo = users[msg.sender];
        userInfo.expire = block.timestamp + lockTime;
        userInfo.amount = msg.value;
    }

    function withdraw() public {
        require(block.timestamp>=users[msg.sender].expire);
        locked storage userInfo = users[msg.sender];
        uint256 value = userInfo.amount;
        userInfo.expire = 0;
        userInfo.amount = 0;
        msg.sender.transfer(value);
    }



}

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.