signMessage()

Use agent.signMessage() to cryptographically sign messages on EVM networks. Supports both EIP-191 (simple text messages) and EIP-712 (typed structured data) signing standards. Returns signature components (v, r, s) and a formatted signature string. Commonly used for authentication, off-chain orders, and proving wallet ownership.

Signature

agent.signMessage(
  request: {
    network: string;
    request: {
      messageType: "eip191" | "eip712";
      chainId: number;
      data: object;
    };
  }
): Promise<SignMessageResponse>

Parameters

Param
Type
Description

request

object

Message signing configuration

request.network

string

Network identifier: 'ethereum:{chainId}' | 'solana'

request.request

object

Transaction details

request.request.messageType

string

Signing standard to use; 'eip191' | 'eip712'

request.request.chainId

number

Ethereum Chain ID

request.request.data

object

Message data (see formats below)

EIP-191 Data Format

For simple message signing

data: {
  message: string  // Plain text message to sign
}

EIP-712 Data Format

For typed structured data

data: {
  domain: object;      // Domain separator
  types: object;       // Type definitions
  primaryType: string; // Primary type name
  message: object;     // Actual message data
}

Returns

  • Promise<SignMessageResponse>

type SignMessageResponse = {
  success: boolean;
  data?: {
    v: number;                  // Signature v component
    r: string;                  // Signature r component (hex)
    s: string;                  // Signature s component (hex)
    formattedSignature: string; // Complete signature (hex)
    type: "evm";                // Always "evm"
  };
  error?: string;               // Error message (only present on failure)
  errorMessage?: string;        // Detailed error info (only present on failure)
}
  errorDetails?: object;
}

Examples

EIP-191 (Simple Message)

const result = await agent.signMessage({
  network: "ethereum:1",
  request: {
    messageType: "eip191",
    data: { message: "Hello, world!" },
    chainId: 1
  }
});

if (result.success && result.data) {
  await agent.log(`Signature: ${result.data.formattedSignature}`);
}

EIP-712 (Typed Data)

const result = await agent.signMessage({
  network: "ethereum:137",
  request: {
    messageType: "eip712",
    chainId: 137,
    data: {
      domain: { name: "MyApp", version: "1", chainId: 137 },
      types: { 
        Order: [
          { name: "maker", type: "address" },
          { name: "amount", type: "uint256" }
        ]
      },
      primaryType: "Order",
      message: { 
        maker: "0x742d35cc6634C0532925a3b8D65e95f32B6b5582",
        amount: "1000000"
      }
    }
  }
});

if (result.success && result.data) {
  await agent.log("Order signed successfully");
}

Common Errors

Error
Cause
Solution

"Invalid chain ID"

Chain ID doesn't match network

Ensure chainId matches network (e.g., mainnet is 1, or ethereum:1)

"Invalid EIP-712 data"

Malformed typed data structure

Validate domain, types, primaryType, and message format

"Invalid message"

Empty or malformed message for EIP-191

Ensure data.message is a non-empty string

Last updated