Let me try to specify my question with an example:

Consider that there are two accounts(AccountA and AccountB), and AccountA wants to send some ether to AccountB when a specific condition is met(i.e. if balance of AccountA is greater than 100).

If i were try to implement this case with centralized way, i would do following:

  • AccountA accepts an agreement(above condition)
  • When AccountB requests to receive ether(based on agreement), centralized app checks condition and if condition is true the app gives ether to AccountB(without AccountA's permission).

So my question:

Can i implement above case via smart contracts?

If i can, how?


Yes you can create a smart contract between two or more parties where there are extra requirements to withdraw ether.

For example multisig wallet allows transfer above certain amount if the transaction is confirmed by several parties.

Simple withdraw

mapping(address => uint) balances;

// I am the sender. if my balance > limit this receiver can take my 1 ether 
function Accept(address _receiver) payable {
    arr[msg.sender] = _receiver;
    balances[_receiver] += msg.value;

// I am the receiver and the sender gave me 1 ether. i wants to receive it.
function Take(address sender){
    if (msg.sender != arr[sender]) 
    if (balances[msg.sender] < limit)
    balances[msg.sender] -= limit;
  • Thanks for your answer. I am trying to write a smart contract to implement my case and i have a trouble. Could you take a look at my sample code gist.github.com/anonymous/77b240dcbac0a769a510ab091554e20e . I couldn't solve sending ether from sender to recevier. Sep 11 '17 at 10:35
  • 1
    You cannot withdraw from an account. You use the contract as a sort of vault holding the ethers until the conditions are met. I've added a small example in the answer.
    – Ismael
    Sep 11 '17 at 14:43
  • Can the sender use all balances until the receiver calls take function? Sep 11 '17 at 14:54
  • 1
    You can add an option so the sender can withdraw the ether if it was not reclaimed in a period of time. .
    – Ismael
    Sep 11 '17 at 17:38

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.