sign_message()

Use agent.sign_message() 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.sign_message(
    request: {
        messageType: "eip191" | "eip712",
        chainId: int,
        data: dict
    }
) -> EvmMessageSignResponse

Parameters

Param
Type
Description

request

dict

Message signing configuration

request.messageType

str

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

request.chainId

int

Ethereum Chain ID

request.data

dict

Message data (see formats below)

EIP-191 Data Format

For simple message signing

data: {
    message: str  # Plain text message to sign
}

EIP-712 Data Format

For typed structured data

data: {
    domain: dict,       # Domain separator
    types: dict,        # Type definitions
    primaryType: str,   # Primary type name
    message: dict       # Actual message data
}

Returns

  • EvmMessageSignResponse

class EvmMessageSignResponse:
    success: bool
    data: {
        status: int,               # HTTP status code
        v: int,                    # Signature v component
        r: str,                    # Signature r component (hex)
        s: str,                    # Signature s component (hex)
        formattedSignature: str,   # Complete signature (hex)
        type: "evm"                # Always "evm"
    } | None
    error: str | None              # Error message (only present on failure)
    error_details: dict | None     # Detailed error info (only present on failure)

Examples

EIP-191 (Simple Message)

response = agent.sign_message({
    "messageType": "eip191",
    "chainId": 1,
    "data": {
        "message": "Hello, world!"
    }
})

if response.success and response.data:
    agent.log(f"Signature: {response.data.formattedSignature}")
    agent.log(f"Status: {response.data.status}")
else:
    agent.log(f"Error: {response.error_message}", error=True)

EIP-712 (Typed Data)

response = agent.sign_message({
    "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 response.success and response.data:
    agent.log("Order signed successfully")
    agent.log(f"Signature: {response.data.formattedSignature}")

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