Skip to main content

Asset Transfer Transaction

Create and send an asset payment transaction to be signed by the user already engaged.

Preconditions#

  • User is already engaged and shared some account.

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

Interactive Example#

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 a asset payment transaction to be sign by the user. There are two alternatives to create 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 txn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
    suggestedParams: {
        ...params,
    },
    from: sender,
    to: receiver,
    assetIndex: 12400859,
    amount: amount,
    note: note
});

const myAlgoConnect = new MyAlgoConnect();
const signedTxn = await myAlgoConnect.signTransaction(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 txn = {
    ...params,
    type: 'axfer',
    from: sender,
    to: receiver,
    assetIndex: 12400859,
    amount: amount,
    note: note
};

const myAlgoConnect = new MyAlgoConnect();
const signedTxn = await myAlgoConnect.signTransaction(txn);