algo-builder
algo-builder copied to clipboard
Getting warning for opt out of asset transaction in Mocha
Describe the bug
As per my understanding, for opting out of a transaction in Algo-builder, we need to send a AssetTransfer
transaction with amount 0, receiver as ourselves and closeRemainderTo
set to the creator address.
const optOutTxn = {
type: types.TransactionType.TransferAsset,
sign: types.SignType.SecretKey,
fromAccount: customer.account,
toAccountAddr: customer.account.addr,
assetID: nft_id,
amount: 0,
payFlags: { totalFee: 1000, closeRemainderTo: seller.account.addr },
};
An example on your repo can be found here: https://github.com/scale-it/algo-builder/blob/326d6d34a7279dc0efc32cbcab0fc9ad4161c293/examples/permissioned-token/scripts/user/opt-out.js#L20-L30
Although the opt out works fine, I am getting warning printed that the
Expected Behavior
No warnings
Current Behavior
Warning printed
<account address> is already opted in to the asset <asset id>
Possible Solution
In the following function, a console.warn()
is added in Line 390 if asset holding is defined but does not handle the case when the transaction is for opting out.
You can add another if condition to check if closeRemainderTo
field is set to the creator of the Asset which confirms that this transaction is a Opt Out transaction and not opt in.
https://github.com/scale-it/algo-builder/blob/326d6d34a7279dc0efc32cbcab0fc9ad4161c293/packages/runtime/src/account.ts#L387-L402
Steps to Reproduce
- Create an NFT
- Create Opt Out transaction
Environment
- OS: Windows 11
- Node.js version: v16.15.0
- algob version: NA