Skip to main content

Appl Opt-In Transaction

Create and send an opt-in 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 address shared by the user, otherwise user will be alert.

Interactive Example#

Invalid number
In order to run this example, you need to execute connect() method.
The following codes allow you to create and sent to MyAlgo Connect an opt-in 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.makeApplicationOptInTxnFromObject({
    suggestedParams: {
        ...params,
    },
    from: sender,
    appIndex: appIndex,
    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 : any = {
    ...params,
    type: "appl",
    appOnComplete: 1, // OnApplicationComplete.OptInOC
    from: sender,
    appIndex: appIndex,
    note: note,
};

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