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

docs: update create-type md for clearer instructions #455

Merged
merged 3 commits into from
Nov 3, 2023

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Nov 1, 2023

This PR focuses on bringing some clarity based on this comment. We thought it would be beneficial to be a bit more explicit in the docs about not using createType for calls such as api.tx..., api.query... etc.

I also added an example where createType can be used to create a Call.

@TarikGul TarikGul marked this pull request as ready for review November 1, 2023 15:19
@TarikGul TarikGul changed the title [WIP] docs: update create-type md for clearer instructions docs: update create-type md for clearer instructions Nov 1, 2023
Comment on lines 131 to 141
You may want to construct a `Call` type given a specific tx. This can be done via `api.createType('Call', foo)`. It can be useful if you intend on only needing the call hex.

```js
const tx = await api.tx.balances.transfer(BOB, 12345);
const call = api.createType('Call', {
callIndex: tx.callIndex,
args: tx.args,
});

console.log('Call Hex: ', call.toHex());
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recommended approach here is -

console.log(
  'hex = ',
  api.tx.balances.transfer(BOB, 123).method.toHex()
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good to know, I actually thought wrong about how to create a call for a while then! Thanks for letting me know and I will have it corrected above!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, i just applied the fix. I went with the direction of advising using api.tx.balances.transfer(BOB, 123).method.toHex() instead of a createType('Call', foo). If you would like as well I can also remove that whole section all together. It might be useful though since even I didnt realize you can grab the method from the tx itself.

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@jacogr jacogr merged commit a56afda into polkadot-js:master Nov 3, 2023
1 check passed
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants