Skip to content

Getting warning for opt out of asset transaction in Mocha #712

Open
@kashishkhullar

Description

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:

const optOutParams = [
{
type: types.TransactionType.TransferAsset,
sign: types.SignType.SecretKey,
fromAccount: account,
toAccountAddr: account.addr,
assetID: tesla.assetIndex,
amount: 0,
payFlags: { totalFee: 1000, closeRemainderTo: tesla.creator },
},
];

Although the opt out works fine, I am getting warning printed that the is already opted in to the asset

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.

optInToASA(assetIndex: number, assetHolding: AssetHoldingM): void {
const accAssetHolding = this.assets.get(assetIndex); // fetch asset holding of account
if (accAssetHolding) {
console.warn(`${this.address} is already opted in to asset ${assetIndex}`);
} else {
if (this.createdAssets.size + this.assets.size === MAX_ALGORAND_ACCOUNT_ASSETS) {
throw new RuntimeError(RUNTIME_ERRORS.ASA.MAX_LIMIT_ASSETS, {
address: assetHolding.creator,
max: MAX_ALGORAND_ACCOUNT_ASSETS,
});
}
this.minBalance += ASSET_CREATION_FEE;
this.assets.set(assetIndex, assetHolding);
}
}

Steps to Reproduce

  1. Create an NFT
  2. Create Opt Out transaction

Environment

  • OS: Windows 11
  • Node.js version: v16.15.0
  • algob version: NA

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions