I've written multi-agent-transaction implementation using Aptos Typescript SDK.
Steps
Create a new TransactionBuilderRemoteABI instance using the aptosClient and sender address
const builder = new TransactionBuilderRemoteABI(aptosClient, {
sender: sender.address(),
});
Build the raw transaction with the specified parameters (e.g., function, type_args, args)
const rawTxn = await builder.build(
"0x15c92120b0aaeb45ee1b7f7d5b0719a3ca1471ef841ccf99561523ff86039219::TwoByTwo::exchange",
[],
[10000, 20000]
);
Create a new MultiAgentRawTransaction instance using the raw transaction and receiver address
const multiAgentTxn = new TxnBuilderTypes.MultiAgentRawTransaction(rawTxn, [
TxnBuilderTypes.AccountAddress.fromHex(receiver.address()),
]);
Sign the transaction with the sender and receiver signatures
const senderSignature = new TxnBuilderTypes.Ed25519Signature(
sender
.signBuffer(TransactionBuilder.getSigningMessage(multiAgentTxn))
.toUint8Array()
);
const receiverSignature = new TxnBuilderTypes.Ed25519Signature(
receiver
.signBuffer(TransactionBuilder.getSigningMessage(multiAgentTxn))
.toUint8Array()
);
Create new AccountAuthenticatorEd25519 instances for the sender and receiver
const senderAuthenticator = new TxnBuilderTypes.AccountAuthenticatorEd25519(
new TxnBuilderTypes.Ed25519PublicKey(sender.signingKey.publicKey),
senderSignature
);
const receiverAuthenticator = new TxnBuilderTypes.AccountAuthenticatorEd25519(
new TxnBuilderTypes.Ed25519PublicKey(receiver.signingKey.publicKey),
receiverSignature
);
Create a new multi-agent authenticator with the sender and receiver authenticators
new TxnBuilderTypes.TransactionAuthenticatorMultiAgent(
senderAuthenticator,
[TxnBuilderTypes.AccountAddress.fromHex(receiver.address())], // Secondary signer addresses
[receiverAuthenticator] // Secondary signer authenticators
);
Convert the signed transaction to bytes using the BCS library
const bcsTxn = BCS.bcsToBytes(
new TxnBuilderTypes.SignedTransaction(rawTxn, multiAgentAuthenticator)
);
Submit the signed BCS transaction to the Aptos client and log the transaction hash
const transactionRes = await aptosClient.submitSignedBCSTransaction(bcsTxn);
console.log(transactionRes.hash);
The complete code is here. If you have any issues let me know in the comments.