0

I made an arrangement with a friend in which he agreed to give me 1% of all the Ethereum that he sells at the time of sale. So he owns 100 Ether today; in 1 year he goes to sell 10 Ether, I would be sent 0.1 Ether from his account at that moment.

How would I go about capturing this in an Ethereum contract? I'm unclear about:

  1. How to "reach into" his account to get 1% of his sale; I'm guessing that he'd need to place 1% of his Ethereum into some "escrow" account up-front?
  2. How to "trigger" an Ethereum contract on the basis of some other event on the blockchain (in particular, the sending of Ether from some particular address).

I'm totally new to Ethereum, so pardon me if I'm getting some of the wording/concepts wrong.

1

Your best bet would be to create a contract that splits the money as it's withdrawn. To do this, you would basically create a contract that only allows your friend to withdraw--but every time he does, it sends 1% of the withdrawal amount to your address.

He would then send his 100 ETH to the contract, knowing he can retrieve it at any time, but doing so pays you the 1% he agreed.

It would probably look something like this:

contract Siphon {
  address private _owner;
  address private _beneficiary;

  modifier onlyOwner {
    if (msg.sender != owner) {
      throw;
    }
    _;
  }

  // alternatively, use the sender to be the owner, so the owner
  // is the deployer.
  function Siphon(address owner, address beneficiary) payable {
    _owner = owner;
    _beneficiary = beneficiary;
  }

  function withdraw(uint256 amount) onlyOwner {
    // note that integer division means amounts less than 100
    // would have no payout
    uint256 beneficiaryAmount = amount / 100;
    if (beneficiaryAmount > 0) {
      if (!_beneficiary.send(beneficiaryAmount)) {
        throw;
      }
    }
    if (!owner.send(amount - beneficiaryAmount)) {
      throw;
    }
  }

  // allow deposits
  function () payable onlyOwner {}
}

I wouldn't use that code straight out of the box, as there are probably some edge cases worth thinking about. I made note of one, at least. It might not quite fit your needs, either, but the core concept should apply: in order to enforce such a restriction on disbursement of ETH, the ETH needs to be owned by the contract, and the events you are interested in (in particular), also need to be managed by the contract.

  • This is what I would propose. But also remember that this subtracts beneficiaryAmount so the friend will receive 9.9 ETH. Also this does not stop him from making the sale outside the contract. – jeff May 6 '17 at 14:54
  • The point would be that the 100ETH that his friend owns goes into this contract as soon as the agreement is made--so the only way he can get it back out is to take the 1% penalty on each withdrawal. The two of them can probably arrange for that 1% to be refunded if the withdrawal isn't for the purposes of selling the ETH. – DeviateFish May 7 '17 at 2:36
  • Yes, the commission can be handled in multiple ways. But the bigger problem here is to track the sell of Ether. What happens when the 100ETH finishes and they go on to new sales? We need an additional mechanism to force the friend to deposit new ethers to the contract as well, or make recipients only accept -internal- transactions from the contract. Anyway, these are problems related to the arrangement itself, and not your answer. I don't have any answer for these either :) – jeff May 7 '17 at 11:46
  • The original arrangement seemed to only be for 100 ETH--plus, the contract I wrote allows for depositing more ETH to be subject to the same rules. Arbitration of the contract, and enforcement of circumstances outside its definition, lie outside the realm of the blockchain--like every other contract. – DeviateFish May 7 '17 at 21:52

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.