signUserOperation
Signs the unsigned UserOperationStruct
returned from buildUserOperation
, buildUserOperationFromTx
, or buildUserOperationFromTxs
actions of the SmartAccountClient
using the account connected to the client.
Usage
import { smartAccountClient } from "./smartAccountClient.ts";
// `buildUserOperation` returns the unsigned user operation struct
// after constructing the user operation struct through the middleware pipeline
const uoStruct = await smartAccountClient.buildUserOperation({
uo: {
target: TO_ADDRESS,
data: ENCODED_DATA,
value: VALUE, // optional
},
});
// signUserOperation signs the above unsigned user operation struct built
// using the account connected to the smart account client
const request = await smartAccountClient.signUserOperation({
uoStruct,
});
// `sendRawUserOperation` to send the signed user operation request by calling
// `sendRawUserOperation` on the client. This sends the signed user op request to the bundler.
// this returns the user operation hash that can be used to wait for the user op txn to be mined on-chain
const entryPointAddress = client.account.getEntryPoint().address;
const uoHash = await smartAccountClient.sendRawUserOperation({
request,
entryPoint: entryPointAddress,
});
const txHash = await smartAccountClient.waitForUserOperationTransaction({
hash: uoHash,
});
console.log(txHash);
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: Hash, request: UserOperationRequest }>
A Promise
containing the signed result of the input UserOperationStruct
using the account connected to the SmartAccountClient
Parameters
SignUserOperationParameters<TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined>
SignUserOperationParameters
export type SignUserOperationParameters<
TAccount extends SmartContractAccount | undefined =
| SmartContractAccount
| undefined,
TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>,
TContext extends UserOperationContext | undefined =
| UserOperationContext
| undefined
> = {
uoStruct: UserOperationStruct<TEntryPointVersion>;
} & GetAccountParameter<TAccount> &
GetContextParameter<TContext>;
uoStruct: UserOperationStruct
The unsigned UserOperationStruct
returned from buildUserOperation
, buildUserOperationFromTx
, or buildUserOperationFromTxs
actions of the SmartAccountClient
returned after running the client middleware pipeline to construct the user operation struct from the input user operation calldata
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.