sendTransactions
This function takes a set of Ethereum transactions and batch converts to one single UserOperation
(UO) struct, signs and sends that UO request, and waits on the receipt of that UO (i.e., has it been mined). If you don't want to wait for the UO to mine, it is recommended to use sendUserOperation instead.
NOTE: Not all Smart Contract Accounts support batching. The SmartContractAccount
implementation must implement the encodeBatchExecute method for the SmartAccountClient
to execute the batched user operation successfully.
Note that to
, data
, value
, maxFeePerGas
, maxPriorityFeePerGas
fields of the transaction request type are considered and used to build the user operation from the transaction, while other fields are not used.
Usage
import { smartAccountClient } from "./smartAccountClient";
const requests: RpcTransactionRequest[] = [
{
from, // ignored
to,
data: encodeFunctionData({
abi: ContractABI.abi,
functionName: "func",
args: [arg1, arg2, ...],
}),
},
{
from, // ignored
to,
data: encodeFunctionData({
abi: ContractABI.abi,
functionName: "func",
args: [arg1, arg2, ...],
}),
},
...
{
from, // ignored
to,
data: encodeFunctionData({
abi: ContractABI.abi,
functionName: "func",
args: [arg1, arg2, ...],
}),
},
];
const txHash = await smartAccountClient.sendTransactions({ requests });
import { createMultiOwnerModularAccount } from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountSigner,
createSmartAccountClient,
polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
const chain = polygonMumbai;
const signer: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
"YOUR_OWNER_MNEMONIC"
);
const rpcTransport = http("https://polygon-mumbai.g.alchemy.com/v2/demo");
export const smartAccountClient = createSmartAccountClient({
transport: rpcTransport,
chain,
account: await createMultiOwnerModularAccount({
transport: rpcTransport,
chain,
signer,
}),
});
Returns
Promise<Hash | null>
A Promise
containing the transaction hash of the batched user operation of the input transactions
Parameters
SendTransactionsParameters<TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined>
SendTransactionsParameters
export type SendTransactionsParameters<
TAccount extends SmartContractAccount | undefined,
TContext extends UserOperationContext | undefined =
| UserOperationContext
| undefined,
TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
> = {
requests: RpcTransactionRequest[];
} & GetAccountParameter<TAccount> &
GetContextParameter<TContext> &
UserOperationOverridesParameter<TEntryPointVersion>;
requests: RpcTransactionRequest[]
The viem
RpcTransactionRequest
type representing a traditional ethereum transaction
overrides?:
UserOperationOverrides
Optional parameter where you can specify override values for maxFeePerGas
, maxPriorityFeePerGas
, callGasLimit
, preVerificationGas
, verificationGasLimit
, paymasterAndData
, or nonceKey
for the user operation request
account?: TAccount extends SmartContractAccount | undefined
When using this action, if the SmartContractAccount
has not been connected to the SmartAccountClient
(e.g. SmartAccountClient
not instantiated with your SmartContractAccount
during createSmartAccountClient
). You can check if the account is connected to the client by checking the account
field of SmartAccountClient
. If the account is not connected, you can specify the SmartContractAccount
instance to use for the function call.