I'm looking to make a smart contract that does the following:

If account X receives Y amount of Eth or tokens, it will send 50% of those coins back to the address that sent it.

How can this be done? Or does this have to be a centralized service? Doesn't this require a 3rd party to monitor this address and then fire the smart contract when it detects activity? Also wouldn't this contract require access to my private keys in order to send those funds back to the sender?

How can this be done in a decentralized way without the need of a 3rd party monitoring service?


No, but yes.

No, structurally and conceptually this cannot be done as stated but you can achieve a similar result.

It cannot be done as stated because nothing can bestow upon a contract the ability to spend someone else's money. Just as a human cannot decide a policy of watching someone else's account and redirecting their receipts, neither can a contract.

Yes, you can make a Splitter contract. You can make a contract that distributes funds it receives according to some rules. So, sender needs to send the funds to the Splitter contract (similar to escrow), and the Splitter contract can have some rules to redistribute all funds received.

Hope it helps.

  • Ah. I understood the question to be asking in the event the contract was the recipient, not a third-party account. – lungj Aug 15 '17 at 20:49
  • So a contract is an entity in itself, but an ethereum address cannot execute any logic? Is this correct? I'm trying to wrap my head around this still. I'm thinking smart contracts are also addresses. From what it looks like any interaction or activity generated on an address cannot execute any type of logic. So in my scenario, a 3rd party is necessary? – Patoshi パトシ Aug 15 '17 at 22:47
  • Everything is an address. "Externally owned accounts" only act when a human or machine signs a transaction. A smart contract is also an address. A smart contract must act according to the programming. It has no choice. So, when someone sends data and/or ether to a smart contract address (a transaction) the smart contract starts following the step-by-step instructions in the contract. – Rob Hitchens - B9lab Aug 15 '17 at 23:57
  • It might helpful (or make it conceptually worse, I'm not sure) to consider that when one designs a smart contract, we do so without knowledge of who or what has invoked a function (we can see the sender address). It might be human, it might be machine or it might be another contract. For your Splitter, the matter is inconsequential. The Splitter would a) receive funds and instructions (send half to Alice and half to Bob) and b) do it. Alice and Bob are themselves just addresses. Those addresses could be wallets or other contracts. The Splitter would be unconcerned about it. – Rob Hitchens - B9lab Aug 16 '17 at 0:00

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.