Learn how to properly prepare data for EVM signing operations with Express API, including message signing and transaction data preparation.
const personalSign = async (data: string) => { // Encode message as base64 const message = Buffer.from(data, 'utf-8').toString('base64'); const body = { message_base64: message }; return await fetch('/v1/wallet/sign/message', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${YOUR_JWT_TOKEN}`, 'X-Magic-API-Key': 'YOUR_MAGIC_API_KEY', 'X-OIDC-Provider-ID': 'YOUR_OIDC_PROVIDER_ID', 'X-Magic-Chain': 'ETH' }, body: JSON.stringify(body) }); };
import { typedSignatureHash } from '@metamask/eth-sig-util'; const signTypedDataV1 = async (data: TypedDataV1) => { // Compute hash for typed data V1 const rawDataHash = typedSignatureHash(data); const body = { raw_data_hash: rawDataHash }; return await fetch('/v1/wallet/sign/data', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${YOUR_JWT_TOKEN}`, 'X-Magic-API-Key': 'YOUR_MAGIC_API_KEY', 'X-OIDC-Provider-ID': 'YOUR_OIDC_PROVIDER_ID', 'X-Magic-Chain': 'ETH' }, body: JSON.stringify(body) }); };
Was this page helpful?