In the ethereum contract, I want to make sender to send some eth to the contract, the receiver can receive the eth in a limited time(ex, 100 seconds), after the expiry, if the eth is still not received by the receiver, the contract will return it to the sender.

The simple code is shown below, however I don't know how to implement the refund, which will automatically check and return the eth to the sender. Can the contract evm has a timer to check on a schedule?

  function create(address _sender, address _receiver)  external payable 
            _sender = _sender;
            _receiver = _receiver
            _expiry = block.timestamps + 100;
            number = number + 1;

  function accept(address _receiver,uint32 _value) external {
     require(_expiry > block.timestamps);

  function refund(){


1 Answer 1


Nothing can happen in a contract without a transaction, so someone will have to tell the contract to do something. E.g. this function from https://programtheblockchain.com/posts/2018/02/23/writing-a-simple-payment-channel/:

// If the timeout is reached without the recipient closing the channel, then
// the ether is released back to the sender.
function claimTimeout() public {
    require(now >= expiration);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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