-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.ts
More file actions
55 lines (47 loc) · 1.38 KB
/
utils.ts
File metadata and controls
55 lines (47 loc) · 1.38 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
createSignerFromKeypair,
keypairIdentity,
UmiPlugin,
} from "@metaplex-foundation/umi";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { Cluster, clusterApiUrl, Keypair } from "@solana/web3.js";
import * as readline from "readline";
import {
createSdpHelloWorldProgram,
getSdpHelloWorldProgram,
initialize,
} from "./client/umi/src";
import { base58 } from "@metaplex-foundation/umi/serializers";
import { getKeypairFromFile } from "@solana-developers/helpers";
export async function getInput(greetingMessage: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
try {
const input = await new Promise<string>((resolve) => {
rl.question(greetingMessage, resolve);
});
return input;
} finally {
rl.close();
}
}
export const initializePrereqs = async (cluster: Cluster, keypair: Keypair) => {
const umi = createUmi(clusterApiUrl(cluster), {
commitment: "confirmed",
});
const admin = umi.eddsa.createKeypairFromSecretKey(keypair.secretKey);
umi.use(keypairIdentity(admin));
const program = (): UmiPlugin => ({
install(umi) {
umi.programs.add(createSdpHelloWorldProgram());
},
});
umi.use(program());
return {
umi,
program: getSdpHelloWorldProgram(umi),
admin: createSignerFromKeypair(umi, admin),
};
};