# Sign Messages

#### Simple Sign

This simply signs a plain string message

```javascript
const signer = wallet.getSigner() 
const message = 'Hello World!'
const signature = await signer.signMessage(message) 
console.log(signature)
```

It gets a Signer instance from the wallet, passes the message string to the signMessage() method, and logs the resulting signature.

#### Sign with EIP712

This signs a more complex EIP712 typed data object:

```javascript
const typedData: sodium.utils.TypedData = {
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: await wallet.getChainId(),
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' }
    ]
  },
  message: {
    name: 'Bob',
    wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
  }
}

const signer = wallet.getSigner()

const signature = await signer.signTypedData(typedData.domain, typedData.types, typedData.message)
console.log(signature)
```

The typedData object describes:

* The domain (contract, chain, version)
* The types of data (Person in this case)
* The actual message to be signed

It then passes these to the signer's signTypedData() method to generate a signature for the typed data object.

This shows how wallet SDKs can be used to:

* Obtain a Signer instance
* Call signMessage() to sign plain strings
* Call signTypedData() to sign more complex EIP712 typed data structures
* Log the resulting signatures


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sodiums.gitbook.io/sodium-documentation/sdk/sign-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
