فهرست منبع

update token2022 basics example

John 1 سال پیش
والد
کامیت
b880f09c99

+ 1 - 1
tokens/token-2022/basics/anchor/Anchor.toml

@@ -9,7 +9,7 @@ url = "https://api.apr.dev"
 
 [provider]
 cluster = "Localnet"
-wallet = "/Users/devenv/.config/solana/id.json"
+wallet = "~/.config/solana/id.json"
 
 [scripts]
 test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

+ 1 - 1
tokens/token-2022/basics/anchor/package.json

@@ -4,7 +4,7 @@
     "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
   },
   "dependencies": {
-    "@coral-xyz/anchor": "^0.27.0"
+    "@coral-xyz/anchor": "^0.30.0"
   },
   "devDependencies": {
     "chai": "^4.3.4",

+ 1 - 3
tokens/token-2022/basics/anchor/programs/basics/Cargo.toml

@@ -18,6 +18,4 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
 
 [dependencies]
 anchor-spl = "0.30.0"
-anchor-lang = { version = "0.30.0", features= ["init-if-needed"]}
-spl-token = { version = "3.1.1", features = ["no-entrypoint"] }
-spl-token-2022 = { version = "0.7.0", features = ["no-entrypoint"] }
+anchor-lang = { version = "0.30.0", features= ["init-if-needed"]}

+ 14 - 16
tokens/token-2022/basics/anchor/tests/anchor.ts

@@ -4,14 +4,15 @@ import { Anchor } from "../target/types/anchor";
 
 describe("anchor", () => {
   // Configure the client to use the local cluster.
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
 
   const program = anchor.workspace.Anchor as Program<Anchor>;
   const connection = program.provider.connection;
   const TOKEN_2022_PROGRAM_ID = new anchor.web3.PublicKey(
     "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
   );
-  const payer = anchor.web3.Keypair.generate();
+  const wallet = provider.wallet as anchor.Wallet;
   const ATA_PROGRAM_ID = new anchor.web3.PublicKey(
     "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
   );
@@ -20,14 +21,14 @@ describe("anchor", () => {
   const [mint] = anchor.web3.PublicKey.findProgramAddressSync(
     [
       Buffer.from("token-2022-token"),
-      payer.publicKey.toBytes(),
+      wallet.publicKey.toBytes(),
       Buffer.from(tokenName),
     ],
     program.programId
   );
   const [payerATA] = anchor.web3.PublicKey.findProgramAddressSync(
     [
-      payer.publicKey.toBytes(),
+      wallet.publicKey.toBytes(),
       TOKEN_2022_PROGRAM_ID.toBytes(),
       mint.toBytes(),
     ],
@@ -47,14 +48,13 @@ describe("anchor", () => {
 
   it("Create Token-2022 Token", async () => {
     await connection.requestAirdrop(receiver.publicKey, 1000000000);
-    await connection.requestAirdrop(payer.publicKey, 1000000000);
+    await connection.requestAirdrop(wallet.publicKey, 1000000000);
     const tx = new anchor.web3.Transaction();
 
     const ix = await program.methods
       .createToken(tokenName)
       .accounts({
-        mint: mint,
-        signer: payer.publicKey,
+        signer: wallet.publicKey,
         tokenProgram: TOKEN_2022_PROGRAM_ID,
       })
       .instruction();
@@ -64,7 +64,7 @@ describe("anchor", () => {
     const sig = await anchor.web3.sendAndConfirmTransaction(
       program.provider.connection,
       tx,
-      [payer]
+      [wallet.payer]
     );
     console.log("Your transaction signature", sig);
   });
@@ -77,7 +77,7 @@ describe("anchor", () => {
       .accounts({
         tokenAccount: payerATA,
         mint: mint,
-        signer: payer.publicKey,
+        signer: wallet.publicKey,
         tokenProgram: TOKEN_2022_PROGRAM_ID,
       })
       .instruction();
@@ -87,7 +87,7 @@ describe("anchor", () => {
     const sig = await anchor.web3.sendAndConfirmTransaction(
       program.provider.connection,
       tx,
-      [payer]
+      [wallet.payer]
     );
     console.log("Your transaction signature", sig);
   });
@@ -124,11 +124,10 @@ describe("anchor", () => {
       .mintToken(new anchor.BN(200000000))
       .accounts({
         mint: mint,
-        signer: payer.publicKey,
+        signer: wallet.publicKey,
         receiver: payerATA,
         tokenProgram: TOKEN_2022_PROGRAM_ID,
       })
-      .signers([payer])
       .instruction();
 
     tx.add(ix);
@@ -136,7 +135,7 @@ describe("anchor", () => {
     const sig = await anchor.web3.sendAndConfirmTransaction(
       program.provider.connection,
       tx,
-      [payer]
+      [wallet.payer]
     );
     console.log("Your transaction signature", sig);
   });
@@ -149,11 +148,10 @@ describe("anchor", () => {
       .transferToken(new anchor.BN(100))
       .accounts({
         mint: mint,
-        signer: payer.publicKey,
+        signer: wallet.publicKey,
         from: payerATA,
         to: receiver.publicKey,
         tokenProgram: TOKEN_2022_PROGRAM_ID,
-        associatedTokenProgram: ATA_PROGRAM_ID,
         toAta: receiverATA,
       })
       .instruction();
@@ -163,7 +161,7 @@ describe("anchor", () => {
     const sig = await anchor.web3.sendAndConfirmTransaction(
       program.provider.connection,
       tx,
-      [payer]
+      [wallet.payer]
     );
     console.log("Your transaction signature", sig);
   });