-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenroll.ts
49 lines (42 loc) · 1.3 KB
/
enroll.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Connection, Keypair, SystemProgram, PublicKey } from "@solana/web3.js";
import {
Program,
Wallet,
AnchorProvider,
Address,
} from "@project-serum/anchor";
import { WbaPrereq, IDL } from "./programs/wba_prereq";
import wallet from "./wba-wallet.json";
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
const connection = new Connection("https://api.devnet.solana.com");
const github = Buffer.from("Kaleb-Rupe", "utf8");
const provider = new AnchorProvider(connection, new Wallet(keypair), {
commitment: "confirmed",
});
const program = new Program<WbaPrereq>(
IDL,
"HC2oqz2p6DEWfrahenqdq2moUcga9c9biqRBcdK3XKU1" as Address,
provider
);
const enrollment_seeds = [Buffer.from("prereq"), keypair.publicKey.toBuffer()];
const [enrollment_key, _bump] = PublicKey.findProgramAddressSync(
enrollment_seeds,
program.programId
);
(async () => {
try {
const txhash = await program.methods
.complete(github)
.accounts({
signer: keypair.publicKey,
prereq: enrollment_key,
systemProgram: SystemProgram.programId,
})
.signers([keypair])
.rpc();
console.log(`Success! Check out your TX here:
https://explorer.solana.com/tx/${txhash}?cluster=devnet`);
} catch (e) {
console.error(`Oops, something went wrong: ${e}`);
}
})();