Is there a way to find out if an account has already opted in to receive an asset? Otherwise, we will need to maintain this information in our application to prevent sending 0 value transactions multiple times to opt in.
You can use the algod REST API or any SDK to do it.
Here is an example with the algoexplorer API endpoint:
$ curl -s https://algoexplorerapi.io/v2/accounts/UK2GUCW2K4V3BCJU5EIPQYX37I7K4LRKM6KSHVWKT3QD2W6JHMWI3H6U2Q | jq
{
"address": "UK2GUCW2K4V3BCJU5EIPQYX37I7K4LRKM6KSHVWKT3QD2W6JHMWI3H6U2Q",
"amount": 200000,
"amount-without-pending-rewards": 200000,
"apps-local-state": [],
"apps-total-schema": {
"num-byte-slice": 0,
"num-uint": 0
},
"assets": [
{
"amount": 15256789,
"asset-id": 135464366,
"creator": "ABKFIENZR4YXOTTWTQCOJ5NNG4CXGRNTR3VMHYNDHE5UQZ6Y2DSCIY772U",
"is-frozen": false
}
],
"created-apps": [],
"created-assets": [],
"pending-rewards": 0,
"reward-base": 182866,
"rewards": 0,
"round": 13591552,
"status": "Offline"
}
The list of assets the account is opted in is assets
.