Payment Transaction with overrided signer
Create and sign a payment transaction to be signed by a specific account.
This example is specific for the signTransaction
method. The new signTxns
method does not yet support this feature.
Preconditions
User has a wallet and has shared an account with the site
Signer to override should match with one of address shared by the user, otherwise user will be alert.
Interactive Example
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 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.makePaymentTxnWithSuggestedParamsFromObject({
suggestedParams: {
...params,
},
from: sender,
to: receiver,
amount: amount,
note: note
});
const signOptions: SignTransactionOptions = {
overrideSigner: overrideAccount
};
const myAlgoConnect = new MyAlgoConnect();
const signedTxn = await myAlgoConnect.signTransaction(txn.toByte(), signOptions);
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: "pay",
from: sender,
to: receiver,
amount: amount,
note: note
};
const signOptions: SignTransactionOptions = {
overrideSigner: overrideAccount
};
const myAlgoConnect = new MyAlgoConnect();
const signedTxn = await myAlgoConnect.signTransaction(txn, signOptions);