Sign MultiAgent Transaction
signMultiAgentTransaction()
signMultiAgentTransaction()
If you are logged in to Face Wallet, users can sign multi-agent transactions. When signing a transaction, users would review the transaction information and enter the PIN code through Face Wallet modal.
You should submit signed transaction data to APTOS node to execute the transaction.
import { Face, Network } from '@haechi-labs/face-sdk';
import { AptosClient, TxnBuilderTypes } from 'aptos';
const face = new Face({
network: Network.APTOS_TESTNET,
apiKey: 'YOUR_DAPP_API_KEY'
});
const aptosProvider = face.aptos.getProvider();
const aptosClient = new AptosClient('APTOS_NODE_URL');
// Dapp should choose the input required to send transaction
const userWalletAddress = (await aptosProvider.getAddresses())[0];
const userWalletPublicKey = (await aptosProvider.getPublicKeys())[0];
const feePayerAddress = "FEE_PAYER_ADDRESS";
const receiverAddress = "RECEIVER_ADDRESS";
const payerAccountData = await aptosClient.getAccount(feePayerAddress);
const sequenceNumber = parseInt(feePayerAddress.sequence_number);
const rawTransaction = await aptosClient.generateTransaction(
feePayerAddress,
{
arguments: [
receiverAddress,
createPlatformCoin(amount, networkToBlockchain(network)).toDecimalAmountAsString(),
],
function:
'{Address}::{Module}::{Function}',
type_arguments: [],
},
{
sequence_number: sequenceNumber.toString(),
}
);
const multiAgentRawTx = new TxnBuilderTypes.MultiAgentRawTransaction(rawTransaction, [
TxnBuilderTypes.AccountAddress.fromHex(userWalletAddress),
]);
const signature = await aptosProvider.signMultiAgentTransaction(multiAgentRawTx);
const payerSignature = 'signed transaction signature with feePayer';
const payerAuthenticator = new TxnBuilderTypes.AccountAuthenticatorEd25519(
new TxnBuilderTypes.Ed25519PublicKey(payerAccount.pubKey().toUint8Array()),
new TxnBuilderTypes.Ed25519Signature(payerSignature.toUint8Array())
);
const senderAuthenticator = new TxnBuilderTypes.AccountAuthenticatorEd25519(
new TxnBuilderTypes.Ed25519PublicKey(userWalletPublicKey.toUint8Array()),
new TxnBuilderTypes.Ed25519Signature(HexString.ensure(signature).toUint8Array())
);
const multiAgentAuthenticator = new TxnBuilderTypes.TransactionAuthenticatorMultiAgent(
payerAuthenticator,
[TxnBuilderTypes.AccountAddress.fromHex(senderAddress)],
[senderAuthenticator]
);
const signedTx = new TxnBuilderTypes.SignedTransaction(
multiAgentRawTx.raw_txn,
multiAgentAuthenticator
);
const pendingTransaction = await aptosClient.submitTransaction(BCS.bcsToBytes(signedTx));
await aptosClient.waitForTransaction(pendingTransaction.hash);
Updated about 1 year ago