How to do atomic transfer with lsig and normal transactions in algosigner?

I have issue in Atomic transfer:
code:

let results = await algodclient.compile(data).do();
console.log("Resultconsole = " + results);
console.log("Hash = " + results.hash);
console.log("Result = " + results.result);
// await sleep(20000)
let program = new Uint8Array(Buffer.from(results.result, "base64"));
let args = [];
args.push(algosdk.encodeUint64(40539489));
args.push(algosdk.encodeUint64(40516573)); //usdc
args.push(algosdk.encodeUint64(40517020));
//args.push(algosdk.encodeUint64(5));
let lsig = algosdk.makeLogicSig(program, args);
console.log("LSIG", lsig.address())
//escrow end
//changes
let txn_b64_1 = tx1.toByte();
let txn_b64_2 = tx2.toByte();
let txn_b64_3 = tx3.toByte();
// let base64Txs1 =  AlgoSigner.encoding.msgpackToBase64(txn_b64_1);
// let base64Txs2 =  AlgoSigner.encoding.msgpackToBase64(txn_b64_2);
console.log("signing")

let base64Txs1 = AlgoSigner.encoding.msgpackToBase64(txn_b64_1);
let base64Txs2 = AlgoSigner.encoding.msgpackToBase64(txn_b64_2);
let base64Txs3 = AlgoSigner.encoding.msgpackToBase64(txn_b64_3);
console.log("encoded")
let signedTxs51 = await AlgoSigner.signTxn([
    {
        txn: base64Txs1,
    },
    {
        txn: base64Txs2,
    },
    {
        txn: base64Txs3,
    }
]);
//console.log("logic",signedTxs5)

let binarySignedTxs1 = AlgoSigner.encoding.base64ToMsgpack(signedTxs51[0].blob);
let binarySignedTxs2 = AlgoSigner.encoding.base64ToMsgpack(signedTxs51[1].blob);
let binarySignedTxs3 = AlgoSigner.encoding.base64ToMsgpack(signedTxs51[2].blob);
let rawSignedTxn4 = algosdk.signLogicSigTransactionObject(tx4, lsig);
let rawSignedTxn5 = algosdk.signLogicSigTransactionObject(tx5, lsig);
//let binarySignedTxs = signedTxs.map((txn) => AlgoSigner.encoding.base64ToMsgpack(txn[0].blob));
let signArr43 = [binarySignedTxs1, binarySignedTxs2, binarySignedTxs3, rawSignedTxn4.blob, rawSignedTxn5.blob];
console.log("signed ABOVE SEND")
let trans = await algodclient.sendRawTransaction(signArr43).do();
console.log("Send complete");
//   console.log("txID", trans);
console.log("id", trans.txId);
await waitForConfirmation(algodclient, trans.txId);
console.log("signed")

error:

{message: 'There was a problem validating the transaction(s):…ed in a different order than when it was created.'}
message: "There was a problem validating the transaction(s): The transaction group is incomplete or presented in a different order than when it was created."

— EDIT: code reformat and written in triple backquotes ‘’’

For security reasons, you need to provide all the transactions in the group to AlgoSigner, even those that do not need to be signed.

This means:

let txn_b64_4 = tx4.toByte();
let txn_b64_5 = tx5.toByte();

let base64Txs4 = AlgoSigner.encoding.msgpackToBase64(txn_b64_4);
let base64Txs5 = AlgoSigner.encoding.msgpackToBase64(txn_b64_5);

let signedTxs51 = await AlgoSigner.signTxn([
    {
        txn: base64Txs1,
    },
    {
        txn: base64Txs2,
    },
    {
        txn: base64Txs3,
    },
    {
        txn: base64Txs4,
    },
    {
        txn: base64Txs5,
    }
]);

Note signers: [] that indicates that AlgoSigner should not sign those transactions.

1 Like