Need help with lsig signed atomic transfer using MyAlgo Connect

I’m trying to write a script that has 2 transactions as part of an atomic transfer.

TX1: Send Algos A → B : signed by user A
TX2: Send ASA B → A : signed by pre-generated lsig shared by B

Here’s the code snippet:

  let txArr = [] as any;

  txArr.push({...txn});
  txArr.push({...asatxn});

  const groupID = algosdk.computeGroupID(txArr)

  txArr[0].group = groupID;
  txArr[1].group = groupID;

  console.log(txArr);

  let signedTxn: SignedTx;
  let signedAsaTxn: SignedTx;

  let bdecode = _base64ToArrayBuffer("<INSERT B64 LSIG HERE>");
  let lsig = algosdk.logicSigFromByte(bdecode);

  signedTxn = (await myAlgoWallet.signTransaction(txArr[0]));
  signedAsaTxn = algosdk.signLogicSigTransaction(txArr[1], lsig);

  let signedGroupTxn = [] as SignedTx[];
  signedGroupTxn.push({...signedTxn});
  signedGroupTxn.push({...signedAsaTxn});

  console.log('signedTxn:', signedGroupTxn);

  let raw: any;
  raw = await algodClient.sendRawTransaction((signedGroupTxn).map(s => s.blob)).do();

  console.log('raw:',raw);
  waitForConfirmation(raw.txId);

When I submit the group transaction, I’m getting something like this as an error: “TransactionPool.Remember: transactionGroup: inconsistent group values: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA != QMJJR7SIYWKQXEOAN2RLM35AHQ5UQ63F4EDDSJB6TOOGEBO66GUA”

Any ideas?

1 Like

Hello @anon1023! The problem I see that you are building the asatxn as a normal object and not using the Transaction class from algosdk. When you pass a normal object to signLogicSigTransaction it will build the algosdk Transaction and will not consider the groupID value.
A solution for this is using the makeAssetTransferTxnWithSuggestedParams from algosdk, then assign the groupID and finally call signLogicSigTransaction with the result object.

      let txArr = [] as any;
      txArr.push({...txn});

      // Update here!
      let asaTxn = makeAssetTransferTxnWithSuggestedParamsFromObject({ ...asatxn, suggestedParams });
      txArr.push(asaTxn);

      const groupID = algosdk.computeGroupID(txArr)

      txArr[0].group = groupID;
      txArr[1].group = groupID;

      console.log(txArr);

      let signedTxn: SignedTx;
      let signedAsaTxn: SignedTx;

      let bdecode = _base64ToArrayBuffer("<INSERT B64 LSIG HERE>");
      let lsig = algosdk.logicSigFromByte(bdecode);

      signedTxn = (await myAlgoWallet.signTransaction(txArr[0]));
      signedAsaTxn = algosdk.signLogicSigTransaction(txArr[1], lsig);

      let signedGroupTxn = [] as SignedTx[];
      signedGroupTxn.push({...signedTxn});
      signedGroupTxn.push({...signedAsaTxn});

      console.log('signedTxn:', signedGroupTxn);

      let raw: any;
      raw = await algodClient.sendRawTransaction((signedGroupTxn).map(s => s.blob)).do();

      console.log('raw:',raw);
      waitForConfirmation(raw.txId);

Please, let me know if this solution works.

1 Like

I raised this as an issue at one point (transaction builder - Transaction object constructor undefines groupID value · Issue #241 · algorand/js-algorand-sdk · GitHub).

Thank you so much! That worked. For anyone else hitting a similar issue, just one more thing: you have to to use signLogicSigTransactionObject instead of signLogicSigTransaction.

1 Like