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:

Method Overview

MethodDescription
async signTypedDataSigns structured data using the EIP712 standard

Sign Typed Data

async oktoClient.signTypedData(data: EIP712 Object) generates a cryptographic signature for the structured data.

Parameters

ParameterTypeDescriptionRequired
oktoClientOktoClientInstance of OktoClient obtained from the useOkto hookYes
dataEIP712 ObjectStructured data object to be signedYes

Response

Success Response

Field NameTypeDescription
resultPromise<string>Returns the EIP712-compliant signature of the data