How to read atomic swap data on the blockchain

Hi forum,

I was wondering if you can look at atomic swap data on the Algo blockchain and if there are any developer resources for that purpose. For example, I want to analyze that in the last X number of blocks, this number of ASA(algo standard asset) was swapped for this number of another ASA. How would I be able to look at the transaction object on the blockchain to tell that an atomic swap has occurred?

Thanks for any pointers.

Hi Joseph,

Check out the atomic transfer docs here: Atomic Transfers - Algorand Developer Portal

The indicator of an atomic transfer on the blockchain is the existence of a group ID field as part of the transaction. And this ID will be the same for each transaction that is part of the group (i.e. part of the atomic transfer).

More info on the Group field can be found here.

2 Likes

For sake of curiosity, on Algoexplorer the Atomic Transfers are marked with an icon and you can inspect the group.

1 Like

Hi cusma,

thanks! Do you have to put the group id in the url to see this? Is there a dashboard where you can see all the groups sequentially?

By the way, in the link that you sent, could you help me understand what is going on in this particular atomic swap? It seems to me that this is not exactly a swap but just receiving an asset for the first time (the address sends a 0 balance to itself, then gets 1 pwSensor token from another address) Why do transactions like this need to be grouped together or is it just the developer’s choice?

Thanks

Atomic transfers, also known as group transactions, allow to group multiple transactions so that they are all executed or none of them are executed.

The simplest use case is an atomic swap of two assets: a user wants to sell x units of asset 1 for y unit of asset 2 (or Algos).

However, there are many more use cases of group transactions. Most dApps will use group transactions in non-trivial ways, in particular to allow a stateful smart contract to execute actual transfers of Algos / assets. The reason is that smart contracts can only inspect transactions that are in the group they are in. They cannot read previous transactions of the blockchain.

I actually do not know exactly what the group above is supposed to be doing.
But here is a guess:

  1. (first transaction = bottom) Make the account UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI opt in to the ASA pwSensor (necessary to be able to receive this ASA)
  2. Make the account UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI opt in to the ASA Planets (necessary to be able to receive this ASA)
  3. Send 1 pwSensor to UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI
  4. (top transaction) Freeze pwSensor in UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI so that UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI cannot spend the pwSensor asset it has.

It is unclear why the dApp developer grouped the first two transactions.
However a good reason to group the last two transactions is to ensure that the user UPW63DI63G2M7ZE2POM6JSIR5FHWZRNJCMYAMJ5CWPDSDJA5HPKDHNLBCI cannot spend the pwSensor asset it received.
Otherwise, if the user was fast enough and the transactions were not grouped, it could do it.

1 Like

Thanks for the detailed walkthrough. I think if I’m trying to analyze swap data, I’ll just have to be careful with putting in a lot of checks to make sure different assets with positive balances are actually being swapped between addresses.