Split payment contract (multiple payments in the same transaction?)

Hi all! I am new to Algorand and smart contracts in general, and I am trying to figure out if Algorand would support my use case.

I want to build a transaction where for each amount a percentage is sent to an address. Is it possible to build something like this using Algorand? I am thinking the contract could validate that a payment was sent to a certain address in the same transaction as the payment sent to the contract. However, I can’t find any example where multiple payments are sent in the same transaction, so I don’t know if this is actually supported.

Has anyone worked on something similar before? Thanks!

Hello and welcome to Algorand!

See the split payment contract as an example.

In brief, you can have funds enter an account that is governed by smart contract code, which only allows withdrawals as group transactions to the accounts you specific at the ratio you specify. That is probably the simplest way.

If you need to add more sophisticated state, you could incorporate stateful apps. The stateful app can hold global values that you can access and condition upon by calling it within the group transaction. This article provides more details on the concept of linking stateful and stateless smart contracts if you go this route.

Hi Liz,

This looks exactly like what I am trying to implement. I will read the articles you sent and try to implement this on my side. Thanks you for your help!

We are in the process of upgrading these tutorials to the latest sdk but here is a tutorial in JS for the split contract:

1 Like