Skip to main content
Raw signing lets you sign arbitrary data with an embedded MPC wallet when you need full control over hashing and formatting. This is most useful for non-standard signing flows or chain/app-specific message formats.
Raw signing is currently only available for EVM embedded wallets.

Basic raw signing (hash then sign)

import { keccak256, stringToHex } from 'viem';
import { DynamicWaasEVMConnector } from '@dynamic-labs/sdk-react-core';

const rawMessage = "Hello World";

// primaryWallet should be an EVM embedded wallet
const connector = primaryWallet.connector as DynamicWaasEVMConnector;

// Dynamic expects the message as a hex string (no 0x) when signing a pre-hashed payload
const hash = keccak256(stringToHex(rawMessage)).slice(2);

const signature = await connector.signRawMessage({
  accountAddress: primaryWallet.address,
  message: hash,
});

console.log("Signature:", signature);

Encoding options

Dynamic supports different encoding formats for your raw messages depending on what you need to hash/sign.

Hexadecimal encoding

Most common for blockchain applications. The message is encoded as a hex string.
import { stringToHex } from 'viem';

const message = "Hello World";
const hexEncoded = stringToHex(message);
// Result: "0x48656c6c6f20576f726c64"

UTF-8 text encoding

For plain text messages that don’t require hex encoding.
Hello World

Hash functions

Different hash functions serve different purposes in cryptographic signing.

Keccak256 (Ethereum standard)

import { keccak256, stringToHex } from 'viem';

const message = "Hello World";
const hash = keccak256(stringToHex(message));