-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathchallenge4.ts
78 lines (62 loc) · 2.81 KB
/
challenge4.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
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Connection, Keypair, SystemProgram, PublicKey, LAMPORTS_PER_SOL } 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 {
MPL_TOKEN_METADATA_PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID
} from '@metaplex-foundation/mpl-token-metadata';
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];
// Paste here the mint address for challenge1 token
const mint = new PublicKey("7u7ds4TpkKNAnGeoUTTwbGsJg2wBWTHR7jqK2d2UBD7u");
// Create the PDA for the Challenge1 Vault
const vault = PublicKey.findProgramAddressSync([Buffer.from("vault4"), keypair.publicKey.toBuffer(), mint.toBuffer()], program.programId)[0];
const metadata_program = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
// Create PDA for token metadata
const metadata_seeds = [
Buffer.from('metadata'),
metadata_program.toBuffer(),
mint.toBuffer(),
];
const metadata = PublicKey.findProgramAddressSync(metadata_seeds, metadata_program)[0];
(async () => {
// NB if you get TokenAccountNotFoundError, wait a few seconds and try again!
// Create the ATA for your Wallet
// const ownerAta = getOrCreateAssociatedTokenAccount(
// ???
// );
// Mint some tokens!
// const mintTx = await mintTo(
// ???
// (await ownerAta).address,
// ???
// )
// Complete the Challenge!
// const completeTx = await program.methods.completeChallenge4()
// .accounts({
// owner:
// ata: (await ownerAta).address,
// profile:
// vault:
// metadata:
// mint:
// tokenProgram:
// metadataProgram:
// associatedTokenProgram:
// systemProgram:
// })
// .signers([
// keypair
// ]).rpc();
// console.log(`Success! Check out your TX here:
// https://explorer.solana.com/tx/${completeTx}?cluster=devnet`);
})();