Skip to content

Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Algos and assets

This section is intended for developers who are looking to add support for Algos or Algorand Standard Assets (ASAs) to their applications. For example, if you are a wallet or an exchange developer, this guide is for you. It will give you an overview of the features that we believe are most relevant for your use case and provide links on where to go for more in-depth explanations.

Algos and assets

Users exchange assets using their mobile wallets.

Algo payments and ASA transfers

To get you started quickly, we recommend checking out the SDK getting started pages where you will find code that demonstrates how to create accounts, send Algo payment transactions, and close out accounts in each of the four SDKs.

And for ASAs, the following code will show you how opt-in, transfer, and close out ASA balances.

Continue on for further explanations of these features and links to more details.

Transactions and minimum balances

Transferring ASAs is very similar to transferring Algos. pay transactions exclusively transfer Algos, while axfer transaction exclusively transfer ASAs. The key structural differences between Algo payments and ASA transfers are summarized in the table below.

Field Description Payment (Algos) Transfer (ASAs)
Transaction "type" "pay" "axfer"
Total amount to transfer "amt" "aamt"
Sender "snd" "snd"
Receiver "rcv" "arcv"
Asset Identifier No need to specify an ID since Algos is implied by the transaction type. The value of "xaid" determines the specific asset to be transferred.

Accounts on Algorand require a minimum balance of 100,000 microAlgos. This balance requirement increases by 100,000 microAlgos for each asset holding.

More details on transactions and min. balances


Opting in and out of ASAs

Any account can receive Algos, but a potential recipient of a specific ASA must first opt-in to the asset so that the account holder does not see their minimum balance requirement increase without their knowing.

"Opting In" to an asset is simply an asset transfer of 0, to and from the opting in account as shown in the table below.

Field Description Transfer (ASAs) Opt-In (ASAs)
Transaction "type" "axfer" "axfer"
Total amount to transfer "aamt" "aamt" with value of 0
Sender "snd" "snd" (must be same as "arcv")
Receiver "arcv" "arcv" (must be same as "snd")
Asset Identifier The value of "xaid" determines the specific asset to be transferred. The value of "xaid" determines the specific asset to opt-in to.

"Opting out" of an asset requires specifying an AssetCloseTo ("aclose") field in the Asset Transfer transaction type. This will result in removal of the ASA holding from the sender's account and a decrease in the minimum balance requirement for that account by 100,000 microAlgos.

Closing accounts

In the Algo "pay" transaction, you can close-out an account by specifying an address in the optional CloseRemainderTo ("close") field. The result of this action is that the remaining account balance will be sent to the specified address and the "snd" address will be effectively removed from the ledger.

An account must opt-out of all asset holdings before closing out its Algo balance.

Where to find account balances

Algo and ASA balances are both located in an account's balance record.

GET /v2/accounts/{address}

The Algo balance can be found at the top level under "amount", while multiple ASA balances are contained in an array under "assets".

Algo Balance ASA Balance
"amount": <micro-algo-balance> "assets":[{"amount": <asa-balance>, "asset-id": <asset-id>, ...}, ...]

Accounting for balance updates

If you are doing your own accounting of transactions and updates to balances, be aware that there are a couple of ways that balances can be updated outside of so-called “normal" transactions.

Inner transactions

Transactions can be sent from smart contracts and these are called inner transactions. These transactions can be found in the inner-txns field of the application call transaction that triggered them. See sample output from algod and indexer APIs.

{
    "dt": {
    .
    .
    .
    "inner-txns": [
        {
        "pool-error": "",
        "txn": {
            "txn": {
            "amt": 20000,
            "fee": 1000,
            "fv": 11,
            "lv": 1011,
            "rcv": "GDA5MWDRLWIQ7G2YZABYYLAA2ZCCZYRZTXR35CTCECL52FNUMXYCC2JXYU",
            "snd": "LMTOYRT2WPSUY6JTCW2URER6YN3GETJ5FHTQBA55EVK66JG2QOB32WPIHY",
            "type": "pay"
            }
        }
        }
    ]
    .
    .
    .
            },
    .
    .
    .
        "txn": {
                .
    .
    .
            "type": "appl"
            }
        },
    {

    .
    .
    .

    "inner-txns": [
        {
        "pool-error": "",
        "txn": {
            "txn": {
            "amt": 20000,
            "fee": 1000,
            "fv": 11,
            "lv": 1011,
            "rcv": "GDA5MWDRLWIQ7G2YZABYYLAA2ZCCZYRZTXR35CTCECL52FNUMXYCC2JXYU",
            "snd": "LMTOYRT2WPSUY6JTCW2URER6YN3GETJ5FHTQBA55EVK66JG2QOB32WPIHY",
            "type": "pay"
            }
        }
        }
    ]
    .
    .
    .
}
    {
    "application-transaction":{
        .
        .
        .
        "confirmed-round":1,
        "fee":0,
        "first-valid":0,
        "id":"LWAEU3YRMRPYUF2ARMUOYUYZVQLNECBII3OVDUDPBUQDGGTFL5NA",
        "inner-txns":[
            {
                "asset-transfer-transaction":{
                    "amount":222,
                    "Asset-id":11,
                    "Close-amount":0,
        "receiver":"PIJRXIH5EJF7HT43AZQOQBPEZUTTCJCZ3E5U3QHLE33YP2ZHGXP7O7WN3U",
                "sender":"PT4K5LK4KYIQYYRAYPAZIEF47NVEQRDX3CPYWJVH25LKO2METIRBKRHRAE"
                },
                "close-rewards":0,
                "closing-amount":0,
                "confirmed-round":1,
                "fee":654,
                "first-valid":3,
                "id":"UCNMXYBCHZ5TAORO6BKU5SAPXKPP4WHQEE7SNKS3XBUO63XYZEKQ",
                "intra-round-offset":2,
                "last-valid":0,
                "receiver-rewards":0,
                "round-time":1631812141,
                "sender":"PT4K5LK4KYIQYYRAYPAZIEF47NVEQRDX3CPYWJVH25LKO2METIRBKRHRAE",
                "sender-rewards":0,
                "signature":{

                },
                "tx-type":"axfer"
            }
        ],
        .
        .
        .
    },
    "tx-type":"appl"
}

Rewards

Network rewards are also distributed differently from standard transactions and are available through the algod and indexer APIs. Read this technical overview of rewards for more details.

Rewards technical overview

Rekeying

Algorand provides a feature that allows any account to be rekeyed by signing a transaction for that account over to the new governing key. We call this out here in case understanding the association between public addresses and authorizing keys or logic is important to your use case. Also be aware that accounts can even be rekeyed to a smart contract, which means that the smart contract code will govern it too.

Rekeying