-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue While connecting Frontend #1
Comments
Your first issue may be due to a breaking change in Anchor IDLs. Read more here. I was able to fix a similar issue by ensuring the version of Anchor in anchor.toml on the backend matched that in package.json for the frontend. |
In my case, the frontend and backend have the same version of Anchor. |
Same issue here, I tried switching back to Anchor 0.29.0 and that brought up different issues since the generated IDL was different |
Same issue here. |
All your problems are related to using Anchor 0.30, which had a bunch of breaking changes. I suggest completing the project with 0.29 instead. I'll temporarily sticky the guide to 0.29 and update it to 0.30 when I've fixed all the new issues. Run
0.30 separates the types and the IDL. Instead of just making a types file, you'd copy over:
Put these in front-end/src/anchor and use them like this: import * as idl from "./counter.json";
import type { Counter } from "./counter";
When creating a program interface in Anchor 0.30, you can't add You'd just do sth like export const program = new Program(idl, provider); But I haven't gotten this to work yet cuz provider is breaking.
Likely related to the IDL changes in v0.30 but I can't confirm. |
@adlonymous see above. You need to have 0.29 in all three places. |
Pretty sure, I'm using 0.29.0, but I get in the browser console:
|
Added this into setup.ts and it appears to work now: in setup.ts
in vite.config.ts:
Edit:
Edit 2:
Probalby it's due to the fact I downgraded anchor version without reinitialising the Program. But after I copied idl.ts from repo write to blockchain started working as expected. |
Change Provider To AnchorProvider to fix Provider breaking: https://coral-xyz.github.io/anchor/ts/classes/AnchorProvider.html Let me know if that fixes it for you cause I'm still working on figuring out the idl and typescript changes in Anchor 0.30.0. Why do they do stuff like rename functions and classes and make breaking idl changes? I hate it. I've been trying to get my frontend to work for 3 weeks now, meanwhile the on chain Rust / Anchor side has been really smooth for me when it comes to cross compiling into bytecode, deploying on to localnet and finally doing Anchor Tests. |
Issue Description
I followed all the steps mentioned in the documentation and watched your YouTube video to create a "FullStack Solana development with React and Anchor" project. Everything worked smoothly until I reached the frontend part.
Problem 1: IDL File
In the documentation, it instructs to create a new folder named
anchor
infront-end/src
and copy overtarget/types/counter.ts
(from the Anchor program) to a new file calledidl.ts
. The purpose of this step is to use the IDL to create TypeScript objects for interacting with the program.However, when I opened
target/types/counter.ts
, I found that it's different from what was expected. It contains additional content, and the lineexport const IDL: Counter = { ... }
is missing.My
counter.ts
was like:Problem 2: Error in setup.js
After adding the
setup.js
file, which looks like this:I encountered an error at the line
export const program = new Program<Counter>(IDL, programId, { connection, });
, which says:Problem 3: Error in Frontend
Following the subsequent steps and adding
<CounterState/>
inApp.tsx
, I encountered an error in the frontend console:Steps Taken
Additional Information
solana-cli 1.18.9 (src:9a7dd9ca; feat:3469865029, client:SolanaLabs)
v20.8.0
1.22.22
anchor-cli 0.30.0
The text was updated successfully, but these errors were encountered: