Skip to main content
1 of 4
Edmund Edgar
  • 16.9k
  • 1
  • 29
  • 58

The solution here will depend on whether there is a trusted actor (you?) who can look at the blockchain and work out how much everyone should receive, or whether the contract needs to be able to confirm the right dividend payment itself based on its own history.

In the former case, you have two options:

  • Send the data of appropriate dividend payment to the chain, based on the state at the payout date, saying how much each account should get. But instead of sending all that data to the chain and putting it in storage, which will cost you gas, arrange the data in a merkle tree or a similar hashed data structure, and just send the root hash to the chain. People claiming will have to send the hashes leading up to the root, which will allow the contract to confirm that their payment is in the tree, and send them the money.
  • Calculate the amounts that need to be paid, but instead of sending anything to the chain, just sign a load of data. For each recipient, sign a message with an Ethereum key saying something like, "Account 0xdeadbeef gets 1234 coins". This signature will consist of 3 pieces of data, called v, r and s, plus the hash of the signed message. Send the chain the address that you're doing the signing with. Each user can send those pieces of the data to the chain and claim the money it says they should receive in the message.

If you don't have a trusted actor, and the contract needs to be able to confirm who should get paid itself, then it's a bit harder. Your contract needs to be able to keep a history of each account as it goes, so that it can tell how much money it had at each date or block. Again, this is costly to do in storage, but you can make it somewhat cheaper with a hashed data structure: Each account starts with a hash of zero, then when they make a transaction, a record is created for the change, and hashed, together with the previous hash, and the resulting change is saved back over the last one. The user can then send data to replay this chain, and prove how much money they had at the dividend payment date. See this code for an example; It's not exactly a dividend payment, but it's a similar process.

Edmund Edgar
  • 16.9k
  • 1
  • 29
  • 58