signTypedDataWith6492
This method supports signing typed data for deployed smart accounts, as well as undeployed accounts (counterfactual addresses) using ERC-6492.
Usage
ts
import { smartAccountClient } from "./smartAccountClient";
// sign typed data (works for undeployed and deployed accounts)
const signedTypedDataWith6492 = smartAccountClient.signTypedDataWith6492({
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
types: {
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" },
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" },
],
},
primaryType: "Mail",
message: {
from: {
name: "Cow",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
contents: "Hello, Bob!",
},
});
ts
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>
A Promise
containing the signature of the typed data, additionally wrapped in ERC-6492 format if the account is undeployed.
Parameters
params: SignTypedDataParams
The typed data to sign
domain: TypedDataDomain
-- The typed data domaintypes: Object
-- the type definitions for the typed dataprimaryType: inferred String
-- the primary type to extract from types and use in valuemessage: inferred from types & primaryType
-- the message, inferred from
account?: SmartContractAccount
If your client was not instantiated with an account, then you will have to pass the account in to this call.