signTypedData
Action for signing typed data with a Starknet account.
Import
import { signTypedData } from "starkweb/core";
Usage
index.ts
import { signTypedData } from "starkweb/core";
import { config } from "./config";
const signature = await signTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
});
Parameters
import { type SignTypedDataParameters } from "starkweb/core";
types
TypedData
The type definitions for the structured data.
primaryType
string
The primary type to sign.
message
Record<string, unknown>
The structured data to sign.
index.ts
import { signTypedData } from "starkweb/core";
import { config } from "./config";
const signature = await signTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
});
connector (optional)
Connector | undefined
The connector to use for signing. If not provided, uses the current connector.
index.ts
import { signTypedData } from "starkweb/core";
import { injected } from "starkweb/connectors";
import { config } from "./config";
const connector = injected();
const signature = await signTypedData(config, {
types: {...},
primaryType: "StarknetMessage",
message: {...},
connector,
});
Return Type
import { type SignTypedDataReturnType } from "starkweb/core";
Hex[]
Array of signature components.
Example
example.ts
import { signTypedData } from "starkweb/core";
import { injected } from "starkweb/connectors";
import { config } from "./config";
// Sign with current connector
const signature = await signTypedData(config, {
types: {
StarknetMessage: [
{ name: "message", type: "felt" },
],
},
primaryType: "StarknetMessage",
message: {
message: "Hello Starknet!",
},
});
console.log("Signature:", signature);
// Sign with specific connector
const connector = injected();
const injectedSignature = await signTypedData(config, {
types: {...},
primaryType: "StarknetMessage",
message: {...},
connector,
});
Error
import { type SignTypedDataErrorType } from "starkweb/core";
TanStack Query
import {
type SignTypedDataData,
type SignTypedDataMutate,
type SignTypedDataMutateAsync,
type SignTypedDataVariables,
signTypedDataMutationOptions,
} from "starkweb/query";