forked from AudioBitsStellar/AudioBlock_Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignMessage.ts
More file actions
39 lines (31 loc) · 1.19 KB
/
Copy pathsignMessage.ts
File metadata and controls
39 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// signMessage.ts
import { ethers, Wallet } from 'ethers';
import * as dotenv from 'dotenv';
dotenv.config();
const run = async (): Promise<void> => {
try {
const privateKey = process.env.PRIVATE_KEY_2;
if (!privateKey) {
throw new Error('PRIVATE_KEY is not defined in the environment variables');
}
// 1. Connect to wallet
const wallet: Wallet = new ethers.Wallet(privateKey);
console.log('Wallet connected:', wallet.address);
// 2. Generate message
const message: string = `Audioblocks Login\nNonce: d5cd4f92cfd189dc2fa7ce04e145e767\nEmail: ezeozuechiagoziem@gmail.com`;
console.log('Message to sign:', message);
// 3. Sign the message
const signature: string = await wallet.signMessage(message);
console.log('Signature:', signature);
// 4. Output result
console.log('Wallet Address:', wallet.address);
console.log('Signed Message:', message);
} catch (error: unknown) {
if (error instanceof Error) {
console.error('Error signing message:', error.message);
} else {
console.error('Unknown error:', error);
}
}
};
run();