Message Signing
Sign Typed Data
Learn how to sign a typed data object using the Okto SDK.
The signTypedData()
method generates a signature for a structured data object following the EIP712 standard. This function allows secure message signing using the OktoClient
instance.
Example
import { useOkto } from '@okto_web3/react-sdk';
function SignTypedData() {
const oktoClient = useOkto();
const data = {
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "chainId", type: "uint256" }
],
Test: [
{ name: "message", type: "string" }
]
},
primaryType: "Test",
domain: {
name: "OktoTest",
chainId: 1
},
message: {
message: "Test message"
}
};
async function handleSignTypedData() {
try {
const signature = await oktoClient.signTypedData(data);
console.log("Signed Typed Data:", signature);
} catch (error) {
console.error("Error signing typed data:", error);
}
}
return (
<button onClick={handleSignTypedData}>
Sign Typed Data
</button>
);
}
Note
For error handling:
- Use the error code to debug issues. Refer to the SDK errors and warnings documentation.
- For additional support, check the troubleshooting guide.
Method Overview
Method | Description |
---|---|
async signTypedData | Signs structured data using the EIP712 standard |
Sign Typed Data
async oktoClient.signTypedData(data: EIP712 Object)
generates a cryptographic signature for the structured data.
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
oktoClient | OktoClient | Instance of OktoClient obtained from the useOkto hook | Yes |
data | EIP712 Object | Structured data object to be signed | Yes |
Response
Success Response
Field Name | Type | Description |
---|---|---|
result | Promise<string> | Returns the EIP712-compliant signature of the data |