Home

Awesome

<br /><br />

<h1 align="center">@substrate/txwrapper</h1> <h4 align="center">Helper funtions for offline transaction generation.</h4> <p align="center"> <a href="https://www.npmjs.com/package/@substrate/txwrapper"> <img alt="npm" src="https://img.shields.io/npm/v/@substrate/txwrapper.svg" /> </a> <a href="https://github.com/paritytech/txwrapper/actions"> <img alt="Github Actions" src="https://github.com/paritytech/txwrapper/workflows/pr/badge.svg" /> </a> <a href="https://opensource.org/licenses/Apache-2.0"> <img alt="apache-2.0" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" /> </a> <a href="https://david-dm.org/paritytech/txwrapper"> <img alt="david-dm" src="https://img.shields.io/david/paritytech/txwrapper.svg" /> </a> </p>

<br /><br />

DEPRECATION NOTICE

On 9 June 2021 this repo will stop being supported.

Please use txwrapper-polkadot instead of this package for long term support and more features. This package will be phased out in the future in favor of the packages in txwrapper-core.

If you are a chain builder looking to build a chain specific txwrapper please take a look at txwrapper-core and the guide for chain builders.

Get Started

yarn add @substrate/txwrapper

In a JS/TS file:

import {
  createSignedTx,
  createSigningPayload,
  methods,
} from '@substrate/txwrapper';

const unsigned = methods.balance.transfer(
  {
    dest: 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',
    value: 100,
  },
  {
    // Additional information needed to construct the transaction offline.
  }
);

const signingPayload = createSigningPayload(unsigned, { registry });
// On your offline device, sign the payload.
const signature = myOfflineSigning(signingPayload);

// `tx` is ready to be broadcasted.
const tx = createSignedTx(unsigned, signature, { metadataRpc, registry });

Have a look at the examples to see how you can perform the whole lifecycle of a transaction, from generation to signing to broadcast.

Go to documentation to see all available functions.

Contribute

We welcome contributions. Before submitting your PR, make sure to run the following commands:

Note for Maintainers

All the commits in this repo follow the Conventional Commits spec. When merging a PR, make sure 1/ to use squash merge and 2/ that the title of the PR follows the Conventional Commits spec.

The history of commits will be used to generate the CHANGELOG. To do so, run yarn deploy on the master branch. This command will look at all the commits since the latest tag, bump the package version according to semver rules, and generate a new CHANGELOG.

If you don't want to follow semver or need to do a dry run, consult the standard-version CLI usage docs. Flags for standard-version can be passed to yarn deploy.

yarn deploy, which only does local operations and doesn't push anything, will output more or less the following lines:

$ yarn deploy
yarn run v1.21.1
$ yarn build && standard-version -r minor
$ rimraf lib/ && tsc
✔ bumping version in package.json from 0.3.2 to 0.4.0
✔ outputting changes to CHANGELOG.md
✔ committing package.json and CHANGELOG.md
✔ tagging release v0.4.0
ℹ Run `git push --follow-tags origin master && npm publish` to publish

To publish the new package, run: git push --follow-tags origin master && npm publish. You must have access to the @substrate organization on npm to publish.

Roadmap

Parachain support