Sodium Documentation
  • Overview
    • Security Architecture
    • Key Management
    • Sodium Network
    • Compatible With ERC-4337
    • Trusted Execution Environment
    • Roadmap
  • SDK
    • Connect Wallet
    • Sign Messages
    • Transfer
    • Wallet Connector
      • web3.js
      • web3-react-v8
      • viem
      • wagmi
      • rainbowkit
      • web3-modal-v2
  • Terms
    • Terms of Use for Sodium Wallet
    • Privacy Policy
    • Sodium List of Restricted Regions
Powered by GitBook
On this page
  1. SDK

Sign Messages

Sodium Wallet can sign any message

Simple Sign

This simply signs a plain string message

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:

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

PreviousConnect WalletNextTransfer

Last updated 2 years ago