-
Notifications
You must be signed in to change notification settings - Fork 115
Add api examples to monorepo #1155
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
Conversation
…tch alexandria runtime
|
Could we move the |
Yes it is getting a bit crowded. I think |
| import { BTreeSet } from '@polkadot/types' | ||
| import { types } from '@joystream/types' | ||
|
|
||
| async function main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script only needs to create some types and doesn't need to read state from chain, and therefore shouldn't require creating an api instance or connecting to a node. I this type of scenario, what is the proper way to create a type registry and register our types so we can construct them safely.
cc: @Lezek123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a function to do this in https://github.com/Joystream/joystream/pull/1176/files#diff-9e9b5c1632859d4c7bee5d17dd9f7c5c, it's not well-tested yet, but I think it should work fine. I can move this to another PR if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I spotted this also in pioneer react-api:
https://github.com/Joystream/joystream/blob/iznik/pioneer/packages/react-api/src/typeRegistry.ts
https://github.com/Joystream/joystream/blob/iznik/pioneer/packages/react-api/src/Api.tsx#L179
So it looks "safe" and correct way.
| return | ||
| } | ||
| obj = obj.unwrap() | ||
| console.log(`contentId: ${new joy.media.ContentId(id).encode()}, ipfs: ${obj.ipfs_content_id}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be api.createType('ContentId', id).encode()
I'm not sure if the joy global is very useful at this point, since we should be able to create any type with api.createType().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix 👍
|
|
||
| const substrateWasm = await api.query.substrate.code.at(currentBlockHash) | ||
|
|
||
| console.log(substrateWasm.toHex()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives me just 0x as output (but also happens in Pioneer via Extrinsics tab)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I was surprised by this as well. Does this have anything to do with the limit on the size of Vec you identified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While working on #1177 I noticed that in the augment-api.ts auto-generated by @polkadot/typegen based on runtime metadata there is no substrate module at all.
So i did a little digging and found out that:
- This module is not part of the metadata retrieved via
api.rpc.state.getMetadata()(even when I get it from our current testnet node) - The same query also outputs
0xon current Kusama - It doesn't throw any errors (which happens in case of the
Vecsize limit issue that I ran into)
|
|
||
| wgId.forEach((id) => { | ||
| set.add(new CuratorApplicationId(api.registry, id)) | ||
| set.add(createType(registry, 'CuratorApplicationId', id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found out we can actually use registry.createType() instead, which is probably a better approach (I'm going to change it in @joystream/types too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that is neater, and one less import :)
Basic examples on using the polkadot js api and joystream types, ported from https://github.com/Joystream/joystream-api-examples