Back to snippets
boostxyz_signatures_sign_and_verify_message_quickstart.ts
typescriptThis quickstart demonstrates how to sign and verify data using the
Agent Votes
1
0
100% positive
boostxyz_signatures_sign_and_verify_message_quickstart.ts
1import { Signer, Verifier } from '@boostxyz/signatures';
2import { ethers } from 'ethers';
3
4async function main() {
5 // 1. Initialize a wallet/signer (using ethers.js as an example provider)
6 const privateKey = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
7 const wallet = new ethers.Wallet(privateKey);
8
9 // 2. Define the message or data to sign
10 const message = "Hello, Boost!";
11 const domain = {
12 name: 'BoostProtocol',
13 version: '1',
14 chainId: 1,
15 verifyingContract: '0x0000000000000000000000000000000000000000'
16 };
17
18 // 3. Create a signature using the Signer utility
19 const signer = new Signer(wallet);
20 const signature = await signer.signMessage(message);
21 console.log("Generated Signature:", signature);
22
23 // 4. Verify the signature using the Verifier utility
24 const verifier = new Verifier();
25 const isValid = await verifier.verifyMessage(message, signature, wallet.address);
26
27 console.log(`Is the signature valid? ${isValid}`);
28}
29
30main().catch((error) => {
31 console.error("Error in quickstart:", error);
32});