-
Notifications
You must be signed in to change notification settings - Fork 77
/
wallet.ts
35 lines (29 loc) · 1.03 KB
/
wallet.ts
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
import { Keypair, LAMPORTS_PER_SOL, Connection } from "@solana/web3.js";
import * as fs from 'fs';
const endpoint = 'https://api.devnet.solana.com';
const solanaConnection = new Connection(endpoint);
const keypair = Keypair.generate();
console.log(`Generated a Wallet with PublicKey: `, keypair.publicKey.toString());
const secret_array = keypair.secretKey
.toString()
.split(',')
.map(value=>Number(value));
const secret = JSON.stringify(secret_array); //Convert to JSON string
fs.writeFile('wallet.json', secret, 'utf8', function(err) {
if (err) throw err;
console.log('Wrote secret key to wallet.json.');
});
(async()=>{
const airdropSignature = solanaConnection.requestAirdrop(
keypair.publicKey,
LAMPORTS_PER_SOL,
);
try{
const txId = await airdropSignature;
console.log(`Airdropped 1 SOL. Transaction Id: ${txId}`);
console.log(`https://explorer.solana.com/tx/${txId}?cluster=devnet`)
}
catch(err){
console.log(err);
}
})()