-
Notifications
You must be signed in to change notification settings - Fork 6
/
challenge3.ts
65 lines (49 loc) · 2.27 KB
/
challenge3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Connection, Keypair, SystemProgram, PublicKey } from "@solana/web3.js"
import { Program, Wallet, AnchorProvider, Address, BN } from "@project-serum/anchor"
import { Week1, IDL } from "./programs/week1";
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, mintTo } from "@solana/spl-token";
import wallet from "./wallet/wba-wallet.json"
// We're going to import our keypair from the wallet file
const keypair = Keypair.fromSecretKey(new Uint8Array(wallet));
// Create a devnet connection
const connection = new Connection("https://api.devnet.solana.com");
// Create our anchor provider
const provider = new AnchorProvider(connection, new Wallet(keypair), { commitment: "confirmed"});
// Create our program
const program = new Program<Week1>(IDL, "ctf1VWeMtgxa24zZevsXqDg6xvcMVy4FbP3cxLCpGha" as Address, provider);
// Use the PDA for our CTF-Week1 profile
const profilePda = PublicKey.findProgramAddressSync([Buffer.from("profile"), keypair.publicKey.toBuffer()], program.programId)[0];
// Use the PDA for the Auth account
// const authPda = ???
// Paste here the mint address for challenge1 token
const mint = new PublicKey("<Mint3 Address>");
// Create the PDA for the Challenge2 Vault
const vault = PublicKey.findProgramAddressSync([Buffer.from("vault2"), keypair.publicKey.toBuffer(), mint.toBuffer()], program.programId)[0];
(async () => {
try {
// NB if you get TokenAccountNotFoundError, wait a few seconds and try again!
// // Create the ATA for your Wallet
// const ownerAta = getOrCreateAssociatedTokenAccount(
// ???
// );
// Complete the Challenge!
// const completeTx = await program.methods.completeChallenge3()
// .accounts({
// owner:
// ata: (await ownerAta).address,
// profile:
// authority:
// mint: mint,
// tokenProgram:
// associatedTokenProgram:
// systemProgram:
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Success! Check out your TX here:
// https://explorer.solana.com/tx/${completeTx}?cluster=devnet`);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();