Closed gameuser1982 closed 5 months ago
I solved the issue:
I changed the original counter.ts:
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Counter } from "../target/types/counter";
import { PublicKey } from "@solana/web3.js";
describe("counter", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.Counter as Program<Counter>;
const wallet = provider.wallet as anchor.Wallet;
const connection = provider.connection;
const [counterPDA] = PublicKey.findProgramAddressSync(
[Buffer.from("counter")],
program.programId
);
it("Is initialized!", async () => {
try {
const txSig = await program.methods.initialize().rpc();
const accountData = await program.account.counter.fetch(counterPDA);
console.log(`Transaction Signature: ${txSig}`);
console.log(`Count: ${accountData.count}`);
} catch (error) {
// If PDA Account already created, then we expect an error
console.log(error);
}
});
it("Increment", async () => {
const transactionSignature = await program.methods.increment().rpc();
const accountData = await program.account.counter.fetch(counterPDA);
console.log(`Transaction Signature: ${transactionSignature}`);
console.log(`Count: ${accountData.count}`);
});
});
to the following:
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Counter } from "../target/types/counter";
import { PublicKey, SystemProgram } from "@solana/web3.js";
describe("counter", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.Counter as Program<Counter>;
it("Is initialized!", async () => {
const [counterPDA, counterBump] = await PublicKey.findProgramAddressSync(
[Buffer.from("counter")],
program.programId
);
const txSig = await program.methods.initialize()
.accounts({
user: provider.wallet.publicKey,
counter: counterPDA,
systemProgram: SystemProgram.programId,
})
.signers([]) // If additional signers are needed, they would go here.
.rpc();
console.log(`Transaction Signature: ${txSig}`);
const accountData = await program.account.counter.fetch(counterPDA);
console.log(`Count: ${accountData.count}`);
console.log(`Counter Bump: ${accountData.bump}`);
});
it("Increment", async () => {
const [counterPDA, counterBump] = await PublicKey.findProgramAddressSync(
[Buffer.from("counter")],
program.programId
);
const txSig = await program.methods.increment()
.accounts({
counter: counterPDA,
})
.rpc();
console.log(`Transaction Signature: ${txSig}`);
const accountData = await program.account.counter.fetch(counterPDA);
console.log(`Count: ${accountData.count}`);
});
});
I still don't get why the original code seemed to work for Mr Raza @AlmostEfficient. I am running node v20.12.2 and Solana 1.18.13 so my Node version is slightly newer while my Solana version is slightly older than what was used in Mr Raza's video.
A lot of the criticism regarding Solana posted in this blog seem valid:
https://devlubo.com/blog/why-solana-so-incredibly-stupid-work-rant
I noticed that code from just 2 years ago is completely obsolete and you need to do things completely differently and everything is poorly documented by Solana Labs / Solana Foundation. Even Mr Raza's video from a month ago is obsolete now because he uses Anchor 0.29.0 while the latest version of Anchor is 0.30.0 and it does integration between frontend and blockchain very differently than 0.29.0.
Solana needs to get their shxt together. It's a nightmare to work with.
Even though I found a solution, I am keeping this open in case anyone else needs help.
Yo, this is happening cuz the guide is missing a tiny part - you're supposed to enable seeds as a feature in anchor.toml.
''' [features] seeds = true '''
Please view line 733 in this commit
I've opened a PR to have it updated in the official Solana guide too, just waiting on a merge.
Solana moves fast and things break a lot. Teams are aware and they're working on removing these pains. This particular instance was a mistake on my part. Thanks for your patience <3
All good man! Keep those great videos coming! I love the projects you're coming up with to inspire new solana devs!
I am using Anchor 0.29.0
I keep getting Error: Invalid arguments: counter not provided even after I delete the target folder, run "anchor keys sync", and finally run "anchor test --skip-local-validator".
What is the work around?
Here is the full error:
candid@DESKTOP-5D7VSM9:~/counter$ anchor test --skip-local-validator