1

If I have two people who want to make a payment at a certain time, eg 1pm tomorrow for 1 ETH, can a smart contract perform that task without the payer stating their private key at the time of the transaction? This is akin to a direct debit on a bank account.

I imagine their key would be needed but that cannot be stored in the contract. Is there a workaround for this? Can the hash of the private key be stored?

I understand Escrow would work, but I want to just have the payer pay the payee without be present at the time of the txn.

0

To transfer ether from an account, either that account must be a smart contract (e.g. the escrow pattern) or that account's private key must be used at the time of the transfer.

So the answer to your question is "No" if you mean transferring from an externally owned account (not a smart contract). But if you're willing to have the payer be a smart contract, then it can implement whatever logic you'd like to decide whether to send funds. (Of course, someone still needs to invoke a transaction at the given time, but you could allow that to be done by anyone.)

  • That is what I thought. – Trevor Lee Oakley Nov 13 '18 at 21:59
  • @TrevorOakley One extra thought: you can sign a transaction ahead of time and then only broadcast it later. But the nonce has to be in sequence, so you couldn't send any other transactions in the intervening time (or, more precisely, you'd have to know in advance exactly how many transactions you'd be sending before the designated time arrives). – user19510 Nov 14 '18 at 1:00
  • I get your point - the main issue is the app is required to make multiple payments and that would involve hundreds of signs via a manual process. The solution is I think storing keys server side in the env variable and making the server secure. – Trevor Lee Oakley Nov 14 '18 at 9:18
1

You can do this.

You can use services like Aion to schedule transactions. This system automatically executes the transaction.

You can write a smart contract to schedule the transaction or you can use Aion web app to schedule the transaction using Metamask.

An example of a smart contract that schedules transactions:

pragma solidity ^0.4.24; 

// interface Aion
contract Aion {
    uint256 public serviceFee;
    function ScheduleCall(uint256 blocknumber, address to, uint256 value, uint256 gaslimit, uint256 gasprice, bytes data, bool schedType) public payable returns (uint,address);

}

// Main contract
contract MyContract{
    uint256 public sqrtValue;
    Aion aion;
    address public owner;
    address public myAionaddress;
    uint256 public schId;
    constructor() public{
        owner = msg.sender;
    }

    function scheduleMyfucntion(uint256 transferAmount, address to) public {
        aion = Aion(0xFcFB45679539667f7ed55FA59A15c8Cad73d9a4E);
        bytes memory data = abi.encodeWithSelector(bytes4(keccak256('transfer(uint256)')),to,transferAmount); 
        uint callCost = 200000*1e9 + aion.serviceFee();
        (schId,myAionaddress) = aion.ScheduleCall.value(callCost)( block.timestamp + 1 days, address(this), 0, 200000, 1e9, data, true);
    }

    function transfer(uint256 transferAmount, address to) public {
        require(msg.sender == owner || msg.sender == myAionaddress);
        to.transfer(transferAmount);    
    } 

    function () public payable {}

}

Hope this helps

  • Thanks. I just tried the app. I needed to pay now though - they just hold the money. That is really like escrow. I was looking for a payment like a DD at a bank. The bank make the payment on that day, they do not debit a week before and then complete on the day. – Trevor Lee Oakley Nov 13 '18 at 14:46
  • Look at the example that I just edit. Aion also allows you to deploy your contract and keep the Ether in your account until the time of execution which seems to be what you are looking for. Let me know if it helps you As for the app, yes you need to "pay" in advance but what the app does is to create a contract an save your Ether there. This allows you to cancel the transaction anytime you want before the execution and only you can do it. – Jaime Nov 13 '18 at 15:13
  • How do they protect the account against fraud? If the private keys are used normally but they are not used for an advance txn, then how? – Trevor Lee Oakley Nov 13 '18 at 22:02
  • The transaction schedule is possible because is made from a smart contract, you can not do this from a externally owned account. As you can see in the example the ethereum is sent from the contract that you deploy not from your account. – Jaime Nov 13 '18 at 23:45
  • I get your point. In the actual app hundreds of these are needed and we would end up deploying hundreds of contracts. – Trevor Lee Oakley Nov 14 '18 at 9:27

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.