3

I need to programmatically pack an extrinsic for an RPC, I believe I'm looking for the following front-end functionality:

Please could anyone indicate me relevant packages in the PolkadotJS sources that do the job, maybe some code snippets that demonstrate the codification routine ?

1 Answer 1

2

I believe this is the library you want to use txwrapper-core, is a set of tools to quickly create, test, and maintain a library of helper functions for offline transaction generation with your chain.

An example you can use as a reference about how to use it is here: https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts

First it gets the metadata with state_getMetadata, with this creates the Polkadot's type registry and then it construct the extrinsic with the help of the library @substrate/txwrapper-polkadot. The example also shows you how to generate the signed extrinsic and how to send it to the node within the RPC author_submitExtrinsic.

Another option to encode/decode SCALE with typescript is the library parity-scale-codec-ts. You can see an example of how to use it in this previous StackExchange answer: How to handle XCM encoding and building in JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.