Create a TxWrapper
Expand the offline signing options for users of your chain.
Creating 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.
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.
Goal
Structure the public API of a chain's txwrapper
package.
Use cases
For existing txwrapper
users to easily integrate new txwrappers.
Steps
1. Create a repo using txwrapper-template
txwrapper-template
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 that the txwrapper-core\
is re-exported at the top level to give the user access to its tools.
2. Update package.json
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-export
You 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.
If you just need methods from Substrate or ORML pallets, checkout txwrapper-substrate and txwrapper-orml to see if the methods are already defined.
4. Create a getRegistry method
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 example
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 package
Once you've made sure that versioning makes sense and that the package works locally, refer to this guide to learn how to publish your package to NPM
.
Examples
Resources
How-to use
tx-wrapper-polkadot
Serialization/deserialization unit tests using
jest
Last updated