Skip to content
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

Update type generation section #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

devdanco
Copy link

@devdanco devdanco commented Jul 6, 2023

I would like to update this page because it is no longer functional in the new version 10.+

According to this issue, this is the only correct way to generate those types. An example can be found here.

I can also update the GitHub repository associated with this page to ensure everything is up to date. Please let me know if this is acceptable or if any additional actions are required on my part. Thank you!

@timbrinded
Copy link

This assumes that the user of the type-gen library is running an ESM project, whereas some teams still may be stuck with CJS.

It makes more sense to split out the instructions into two sets (for each ESM / CJS) given both are admirably being supported.

@devdanco
Copy link
Author

devdanco commented Jul 6, 2023

We also have CJS, but currently we are focusing on the ESM release. Could you please show me how to use CJS for typegen? I've tried different things, but I haven't been successful. Thank you.

@peetzweg
Copy link

Thanks this help me a bit getting it up and running. Although still having the following issues. Any ideas how to resolve them? Found this PR while reading through the issues for typegen in 10.x .

ERROR: No custom definitions found: /.../src/interfaces/definitions.ts is not a file

Is this even an ERROR as it's stated, no custom definitions. What the matter with custom definitions? Shouldn't this be just a simple info output instead of an error?

And when typechecking with tsc, I have a bunch of duplicate identifiers.

Screenshot 2023-12-15 at 12 17 59

@devdanco
Copy link
Author

@peetzweg I no longer use tsc; instead, I am using tsx, and the process has become more seamless as we exclusively utilize ESM.

The structural setup is as follows:
For custom types and rpc, it's essential to define them within the interface folder. Refer to the mangata types as an example. In this directory, you'll find the definitions.ts file where we specify our custom types. If you have a custom RPC, such as pos_calculate_native_rewards_amount in Rust, create a folder named 'pos' within the interfaces directory. Inside this 'pos' folder, add a definitions.ts file and include the new method in the rpc object. Don't forget to add an empty types object, as demonstrated here.

Next, within interfaces/definitions.ts, you must export these definitions. Once this setup is complete and you have a metadata.json file, execute the following commands:

"npx tsx node_modules/.bin/polkadot-types-from-defs --package @mangata-finance/types/interfaces --input src/interfaces --endpoint metadata.json",
"npx tsx node_modules/.bin/polkadot-types-from-chain --package @mangata-finance/types/interfaces --endpoint metadata.json --output src/interfaces"

I hope it will help you. If you have any other question feel free to ask. Or you can show the repo and I can help you more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants