Skip to main content

Grouped Transaction

Create and send an atomic payment transaction (2 transactions grouped) to be signed by the user.

Preconditions#

  • User is already engaged and shared some account.

  • Transaction sender should match with one of address shared by the user, otherwise user will be alert.

Interactive Example#

Invalid Address
Invalid Address
In order to run this example, you need to execute connect() method.
The following codes allow you to create and sent to MyAlgo Connect 2 transactions grouped to be sign by the user. There are two alternatives to make it. Pick the one you prefere.
import algosdk from "algosdk";
import MyAlgoConnect from '@randlabs/myalgo-connect';
 
const algodClient = new algosdk.Algodv2("",'https://node.testnet.algoexplorerapi.io', '');
const params = await algodClient.getTransactionParams().do();

const txn1 = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
    suggestedParams: {
        ...params,
    },
    from: sender,
    to: receiver1, 
    amount: amount1
});

const txn2 = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
    suggestedParams: {
        ...params,
    },
    from: sender,
    to: receiver2, 
    amount: amount2
});

const txnsArray = [ txn1, txn2 ];
const groupID = algosdk.computeGroupID(txnsArray)
for (let i = 0; i < 2; i++) txnsArray[i].group = groupID;

const myAlgoConnect = new MyAlgoConnect();
const signedTxns = await myAlgoConnect.signTransaction(txnsArray.map(txn => txn.toByte()));
import algosdk from "algosdk";
import MyAlgoConnect from '@randlabs/myalgo-connect';
 
const algodClient = new algosdk.Algodv2("",'https://node.testnet.algoexplorerapi.io', '');
const params = await algodClient.getTransactionParams().do();

const txn1: any = {
    ...params,
    type: "pay",
    from: sender,
    to: receiver1,
    amount: amount
};

const txn2: any = {
    ...params,
    type: "pay",
    from: sender,
    to: receiver2,
    amount: amount
};

const txnsArray = [ txn1, txn2 ];
const groupID = algosdk.computeGroupID(txnsArray)
for (let i = 0; i < 2; i++) txnsArray[i].group = groupID;

const myAlgoConnect = new MyAlgoConnect();
const signedTxns = await myAlgoConnect.signTransaction(txnsArray);