Skip to content

Go SDK - Multi-Agent Transactions

Multi-agent transactions allow multiple accounts to participate in the logic of a Move contract.

This can be used to require multiple parties agree to a transaction before executing or to use resources from multiple accounts.

Creating and executing a multi-agent transaction follows a similar flow to the regular transaction flow, but with several notable differences.

  1. Build the transaction by including aptos.AdditionalSigners with a list of each additional signers.

    transaction, err := client.BuildTransactionMultiAgent(alice.AccountAddress(), aptos.TransactionPayload{
    Payload: &aptos.EntryFunction{
    // Replace module and function with your multi-agent function
    Module: aptos.ModuleId{
    Address: aptos.AccountOne,
    Name: "aptos_account",
    },
    Function: "transfer",
    ArgTypes: []aptos.TypeTag{},
    Args: [][]byte{
    accountBytes,
    amountBytes,
    },
    },
    AdditionalSigners: []aptos.AccountAddress{bob.AccountAddress()},
    })
  2. Sign once for each signer.

    You will combine these signatures in the next step.

    aliceAuth, err := rawTxn.Sign(alice)
    if err != nil {
    panic("Failed to sign transaction as sender:" + err.Error())
    }
    bobAuth, err := rawTxn.Sign(bob)
    if err != nil {
    panic("Failed to sign transaction as second signer:" + err.Error())
    }
  3. Combine the signatures with the raw transaction to create a multi-agent signed transaction.

    signedTxn, ok := rawTxn.ToMultiAgentSignedTransaction(aliceAuth, []crypto.AccountAuthenticator{bobAuth})
  4. Submit the transaction by combining all agent signatures via the aptos.AdditionalSigners parameter.

    submitResponse, err := client.SubmitTransaction(signedTxn)
  5. Lastly, wait for the transaction to resolve.

    txnResult, err := client.WaitForTransaction(submitResponse.Hash)

NUMBER_OF_SIGNER_ARGUMENTS_MISMATCH - This happens when you are attempting to do multi-agent signing for a function which does not require that number of accounts. For example, if you try using multiple signatures for a 0x1::aptos_account::transfer function - it only expects one address, and so produces an error when more than one is provided.