signTypedDataWith6492
signTypedDataWith6492
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 {
createLightAccount,
lightAccountClientActions,
} from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountSigner,
createSmartAccountClient,
polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
export const chain = polygonMumbai;
export const signer: SmartAccountSigner =
LocalAccountSigner.mnemonicToAccountSigner("YOUR_OWNER_MNEMONIC");
export const rpcTransport = http(
"https://polygon-mumbai.g.alchemy.com/v2/demo"
);
export const smartAccountClient = createSmartAccountClient({
transport: rpcTransport,
chain,
account: await createLightAccount({
transport: rpcTransport,
chain,
signer,
}),
}).extend(lightAccountClientActions);
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