-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature request: anchor keys sync
should export the program id as a const in the TypeScript file
#2710
Comments
We put program id in the IDL after the deploy step and you can access it via |
Thanks for the quick reply. I did look at using the property from the IDL but there I see 2 downsides to this:
I'm happy to give a shot at implementing this but I'm pretty much a Rust noob so any guidance is welcome! |
Yeah, I think this is a problem because we only add the |
I think that makes a lot of sense. Ideally both in |
The IDL spec now requires Added in #2824. |
Very excited to see the new IDL format, great stuff! And while it does serve a part of the issue, there's still this point:
Ideally, we can directly import a symbol like |
Please explain why it is tricky to read JavaScript Object Notation using frontend tooling when the language has first-class support for it?
Is the "parsing logic" that we rely on |
Weirdly enough, the main issue is opening the actual file. Especially when this file is shipped in an npm package. Once read, parsing the json payload is easy. Happy to provide a demo to convince you. Any reason why not to export this as a common symbol? Is it really hard? Does its hurt in any other way? I personally think it will make everybody's life easier. |
Just to be clear, it's a demo of how hard it is to open a JSON file in frontend using JS/TS? I certainly must be missing something and would be happy to see the problem.
The reason is that, the address already exists in the IDL, which is already needed to interact with the program or pretty much any other functionality from the TS package. It is also not a type, which is why the |
Currently, there's no easy way to get the program id from an Anchor program in TypeScript. The developer generally manually copies the id over to their app, which is not ideal.
It would be great if the
keys sync
command could automatically export the program id in the TypeScript file.So when running
anchor keys sync
, next to the program id being synced up inlib.rs
andAnchor.yaml
, it would also add a line totarget/types/<program_name>.ts
:The text was updated successfully, but these errors were encountered: