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 { OktoClient } from '@okto_web3/core-js-sdk';
 
async function SignTypedData() {
    const oktoClient = new OktoClient({ 
        environment: process.env.OKTO_ENVIRONMENT, 
        clientPrivateKey: process.env.OKTO_CLIENT_PRIVATE_KEY, 
        clientSWA: process.env.OKTO_CLIENT_SWA, 
    }); 
    
    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"
        } 
    }; 
 
    const signedTypedData_response = await oktoClient.signTypedData(data);  
    console.log('Signed Typed Data: ', signedTypedData_response);
};

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