Skip to content

Commit b880f09

Browse files
committed
update token2022 basics example
1 parent f2bdbd4 commit b880f09

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

Diff for: tokens/token-2022/basics/anchor/Anchor.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ url = "https://api.apr.dev"
99

1010
[provider]
1111
cluster = "Localnet"
12-
wallet = "/Users/devenv/.config/solana/id.json"
12+
wallet = "~/.config/solana/id.json"
1313

1414
[scripts]
1515
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

Diff for: tokens/token-2022/basics/anchor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
55
},
66
"dependencies": {
7-
"@coral-xyz/anchor": "^0.27.0"
7+
"@coral-xyz/anchor": "^0.30.0"
88
},
99
"devDependencies": {
1010
"chai": "^4.3.4",

Diff for: tokens/token-2022/basics/anchor/programs/basics/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
1818

1919
[dependencies]
2020
anchor-spl = "0.30.0"
21-
anchor-lang = { version = "0.30.0", features= ["init-if-needed"]}
22-
spl-token = { version = "3.1.1", features = ["no-entrypoint"] }
23-
spl-token-2022 = { version = "0.7.0", features = ["no-entrypoint"] }
21+
anchor-lang = { version = "0.30.0", features= ["init-if-needed"]}

Diff for: tokens/token-2022/basics/anchor/tests/anchor.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { Anchor } from "../target/types/anchor";
44

55
describe("anchor", () => {
66
// Configure the client to use the local cluster.
7-
anchor.setProvider(anchor.AnchorProvider.env());
7+
const provider = anchor.AnchorProvider.env();
8+
anchor.setProvider(provider);
89

910
const program = anchor.workspace.Anchor as Program<Anchor>;
1011
const connection = program.provider.connection;
1112
const TOKEN_2022_PROGRAM_ID = new anchor.web3.PublicKey(
1213
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
1314
);
14-
const payer = anchor.web3.Keypair.generate();
15+
const wallet = provider.wallet as anchor.Wallet;
1516
const ATA_PROGRAM_ID = new anchor.web3.PublicKey(
1617
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1718
);
@@ -20,14 +21,14 @@ describe("anchor", () => {
2021
const [mint] = anchor.web3.PublicKey.findProgramAddressSync(
2122
[
2223
Buffer.from("token-2022-token"),
23-
payer.publicKey.toBytes(),
24+
wallet.publicKey.toBytes(),
2425
Buffer.from(tokenName),
2526
],
2627
program.programId
2728
);
2829
const [payerATA] = anchor.web3.PublicKey.findProgramAddressSync(
2930
[
30-
payer.publicKey.toBytes(),
31+
wallet.publicKey.toBytes(),
3132
TOKEN_2022_PROGRAM_ID.toBytes(),
3233
mint.toBytes(),
3334
],
@@ -47,14 +48,13 @@ describe("anchor", () => {
4748

4849
it("Create Token-2022 Token", async () => {
4950
await connection.requestAirdrop(receiver.publicKey, 1000000000);
50-
await connection.requestAirdrop(payer.publicKey, 1000000000);
51+
await connection.requestAirdrop(wallet.publicKey, 1000000000);
5152
const tx = new anchor.web3.Transaction();
5253

5354
const ix = await program.methods
5455
.createToken(tokenName)
5556
.accounts({
56-
mint: mint,
57-
signer: payer.publicKey,
57+
signer: wallet.publicKey,
5858
tokenProgram: TOKEN_2022_PROGRAM_ID,
5959
})
6060
.instruction();
@@ -64,7 +64,7 @@ describe("anchor", () => {
6464
const sig = await anchor.web3.sendAndConfirmTransaction(
6565
program.provider.connection,
6666
tx,
67-
[payer]
67+
[wallet.payer]
6868
);
6969
console.log("Your transaction signature", sig);
7070
});
@@ -77,7 +77,7 @@ describe("anchor", () => {
7777
.accounts({
7878
tokenAccount: payerATA,
7979
mint: mint,
80-
signer: payer.publicKey,
80+
signer: wallet.publicKey,
8181
tokenProgram: TOKEN_2022_PROGRAM_ID,
8282
})
8383
.instruction();
@@ -87,7 +87,7 @@ describe("anchor", () => {
8787
const sig = await anchor.web3.sendAndConfirmTransaction(
8888
program.provider.connection,
8989
tx,
90-
[payer]
90+
[wallet.payer]
9191
);
9292
console.log("Your transaction signature", sig);
9393
});
@@ -124,19 +124,18 @@ describe("anchor", () => {
124124
.mintToken(new anchor.BN(200000000))
125125
.accounts({
126126
mint: mint,
127-
signer: payer.publicKey,
127+
signer: wallet.publicKey,
128128
receiver: payerATA,
129129
tokenProgram: TOKEN_2022_PROGRAM_ID,
130130
})
131-
.signers([payer])
132131
.instruction();
133132

134133
tx.add(ix);
135134

136135
const sig = await anchor.web3.sendAndConfirmTransaction(
137136
program.provider.connection,
138137
tx,
139-
[payer]
138+
[wallet.payer]
140139
);
141140
console.log("Your transaction signature", sig);
142141
});
@@ -149,11 +148,10 @@ describe("anchor", () => {
149148
.transferToken(new anchor.BN(100))
150149
.accounts({
151150
mint: mint,
152-
signer: payer.publicKey,
151+
signer: wallet.publicKey,
153152
from: payerATA,
154153
to: receiver.publicKey,
155154
tokenProgram: TOKEN_2022_PROGRAM_ID,
156-
associatedTokenProgram: ATA_PROGRAM_ID,
157155
toAta: receiverATA,
158156
})
159157
.instruction();
@@ -163,7 +161,7 @@ describe("anchor", () => {
163161
const sig = await anchor.web3.sendAndConfirmTransaction(
164162
program.provider.connection,
165163
tx,
166-
[payer]
164+
[wallet.payer]
167165
);
168166
console.log("Your transaction signature", sig);
169167
});

0 commit comments

Comments
 (0)