Asset transfer by grouping transactions

let xtxn1 = algosdk.makeAssetTransferTxn(sender, recipient,
            closeRemainderTo, revocationTarget, cp.fee, amount,
            cp.firstRound, cp.lastRound, note, cp.genHash, cp.genID, assetID);
        let xtxn2 = algosdk.makeAssetTransferTxn(sender, recipient,
            closeRemainderTo, revocationTarget, cp.fee, amount,
            cp.firstRound, cp.lastRound, note, cp.genHash, cp.genID, assetID);

        var txns = [xtxn1, xtxn2]; // array of unsigned transactions (dict or Transaction)
        var sks = recoveredAccount1.sk;
        let txgroup = algosdk.assignGroupID(txns);
        var signed = [];
        for (let idx in txgroup) {
            signed.push(algosdk.signTransaction(txgroup[idx], sks));
        }
        let xtx = (await algodclient.sendRawTransactions(signed));
        console.log("Asset Transfer Transaction id : " + xtx.txId);
        // wait for transaction to be confirmed
        await waitForConfirmation(algodclient, xtx.txId);

it shows address seems to be malformed error…can anyone help me?

Can you provide a JS file with an example that can be run or at least the exact error output?

Most likely the issue is that one of the variables like sender, recipient, … is not a valid Algorand address.

1 Like

i cant upload a file sir…here is my code…

const algosdk = require('algosdk');

const token = "3c169d2e0b26d9a224bf590304b80410ae70f240c0ca531e297a9c58350b2f11";
const server = "127.0.0.1";
const port = 8080;

// Utility function to update params from blockchain
async function getChangingParms(algodclient) {
    const cp = {};
    let params = await algodclient.getTransactionParams();
    cp.firstRound = params.lastRound;
    cp.lastRound = cp.firstRound + parseInt(1000);
    let sfee = await algodclient.suggestedFee();
    cp.fee = sfee.fee;
    cp.genID = params.genesisID;
    cp.genHash = params.genesishashb64;
    return cp;
}
// Function used to wait for a tx confirmation
const waitForConfirmation = async function (algodclient, txId) {
    let lastround = (await algodclient.status()).lastRound;
    while (true) {
        const pendingInfo = await algodclient.pendingTransactionInformation(txId);
        if (pendingInfo.round !== null && pendingInfo.round > 0) {
            //Got the completed Transaction
            console.log("Transaction " + pendingInfo.tx + " confirmed in round " + pendingInfo.round);
            break;
        }
        lastround++;
        await algodclient.statusAfterBlock(lastround);
    }
};


var algodclient = new algosdk.Algod(token, server, port);
var account1_mnemonic = "sea dove slender worth drop track spy rescue ramp ticket neutral zebra awake inject area future depart above minor choose add used polar abstract pond";
var recoveredAccount1 = algosdk.mnemonicToSecretKey(account1_mnemonic);
var receiveraccount = "april field feature hundred edit crush proud calm elbow need adult joke ready scene tomorrow second crunch dose flash slender sand repeat bid above grow";
var recoveredAccount2 = algosdk.mnemonicToSecretKey(receiveraccount);
var receiveaccount = "session short burden pole tomorrow jungle grit join buzz arm shove lend obscure trumpet edit trim rifle suffer round rate endless hollow boil abstract nose";
var receiveraccount3 = algosdk.mnemonicToSecretKey(receiveaccount);
async function transaction() {
    // Transfer Asset:
    // replace with your  assetid
    try {
        let assetID = 55;
        let sender = recoveredAccount1.addr;;
        let recipient = recoveredAccount2.addr;
        let recipient2 = receiveraccount3.addr;
        let note = undefined;
        // We set revocationTarget to undefined as 
        // This is not a clawback operation
        let revocationTarget = undefined;
        // CloseReaminerTo is set to undefined as
        // we are not closing out an asset
        let closeRemainderTo = undefined;
        // We are sending 0 assets
        amount = 0;

        let cp = await getChangingParms(algodclient);
        console.log(cp);
        console.log(recipient2);

        // signing and sending "txn" allows sender to begin accepting asset specified by creator and index
        let xtxn1 = algosdk.makeAssetTransferTxn(sender, recipient,
            closeRemainderTo, revocationTarget, cp.fee, amount,
            cp.firstRound, cp.lastRound, note, cp.genHash, cp.genID, assetID);
        let xtxn2 = algosdk.makeAssetTransferTxn(sender, recipient2,
            closeRemainderTo, revocationTarget, cp.fee, amount,
            cp.firstRound, cp.lastRound, note, cp.genHash, cp.genID, assetID);

        let txns = [xtxn1, xtxn2]; // array of unsigned transactions (dict or Transaction)
        let sks = recoveredAccount1.sk;
        console.log(sks)
        let txgroup = algosdk.assignGroupID(txns);
        let signed = [];
        for (let idx in txgroup) {
            signed.push(algosdk.signTransaction(txgroup[idx], sks));
        }
        console.log(signed);
        let xtx = (await algodclient.sendRawTransactions(signed));
        console.log("Asset Transfer Transaction id : " + xtx.txId);
        // wait for transaction to be confirmed
        await waitForConfirmation(algodclient, xtx.txId);

        // You should now see the 10 assets listed in the account information
        act = await algodclient.accountInformation(recoveredAccount1.addr);
        console.log("Account Information for: " + JSON.stringify(act.assets[assetID]));
    } catch (e) {
        console.log(e);

    }
}
transaction();

Replace:

signed.push(algosdk.signTransaction(txgroup[idx], sks));

by

signed.push(txgroup[idx].signTxn(sks));

PS: If you wrap your code inside three backquotes ```, it gets pretty printed.

1 Like

sure sir…thanks a lot