Create a `txwrapper` for a chain
๐ฌ
#
GoalStructure the public API of a chain's txwrapper
package.
#
Use casesFor existing txwrapper
users to easily integrate new txwrappers.
#
OverviewCreating a txwrapper
package will expand the offline signing options for users of your chain. This is important for security
conscious users who need to facilitate transaction signing, construction and/or decoding with an air-gapped device(s). This includes
(but is not limited to) custodians, exchanges, and cold storage users.
note
Prior to building a txwrapper
for your own chain, have a look at the txwrapper-examples
. Make sure you understand the Polkadot example and take a look at the txwrapper-core
methods an end user is expected to use (see decode
, construct.{signingPayload, signedTx, txHash}
). Your package will be re-exporting these so be sure to understand the public API you will create.
#
Stepstxwrapper-template
#
1. Create a repo using Copy the txwrapper-template
directory into your working repository.
The template provides the basics of a typescript package near ready for being published to NPM
. The exports show some methods
that are relevant to a FRAME based chain using at least the balances
, proxy
, and utility pallets
.
note
All of txwrapper-core
is re-exported at the top level to give the user access to its tools.
package.json
#
2. Update Modify the following fields to reflect your chains information:
- name
- author
- description
- repository
- bugs
- homepage
- private (mark as false)
Additionally, add the following field to give publishing permission:
#
3. Choose relevant methods to re-exportYou will need to choose what pallet methods you want your txwrapper
to expose. It is recommended to choose methods that are likely to be
signed by keys stored offline.
info
If you just need methods from Substrate or ORML pallets, checkout txwrapper-substrate and txwrapper-orml to see if the methods are already defined.
getRegistry
method#
4. Create a Your txwrapper will need to export a getRegistry
method so users can get a Polkadot-js TypeRegistry
with the most up-to-date types for your chain.
With some small modifications, the foo
example below can be applied to any FRAME
-based chain compatible with Polkadot-js types:
And add relevant exports:
#
5. Create a working exampleinfo
A good example can ease user friction and reduce workload for maintainers. Create an end-to-end example so users have a clear understanding of the full flow for offline transaction generation for your chain.
- Rename
template-example.ts
to something appropriate to your chain and update all the sections in the file marked TODO. - Update
examples/README.md
in the sections marked TODO. - Make sure you can run the example using a development node for your chain.
#
6. Publish your packageOnce you've made sure that versioning make sense and that the package works locally,
refer to this guide to learn how publish your package to NPM
.
#
Examples#
Resources- How-to use
tx-wrapper-polkadot
- Serialization/deserialization unit tests using
jest