This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66d9f71
commit 56743de
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @title Offline Signing | ||
* @stability nearing | ||
* @description Create and sign an extrinsic, then serialize it into a hex for later use. | ||
* Finally, rehydrate the extrinsic and submit it. | ||
*/ | ||
|
||
import { $, SignedExtrinsicRune } from "capi" | ||
import { signature } from "capi/patterns/signature/polkadot.ts" | ||
import { Balances, chain, createUsers } from "westend_dev/mod.js" | ||
|
||
const { alexa, billy } = await createUsers() | ||
|
||
// Create and sign the extrinsic. Extract the hex. | ||
const hex = await Balances | ||
.transfer({ | ||
value: 12345n, | ||
dest: billy.address, | ||
}) | ||
.signed(signature({ sender: alexa })) | ||
.hex() | ||
.run() | ||
|
||
// Save `hex` however you'd like (potentially sending to a relayer service, | ||
// writing to disk, etc.). | ||
save(hex) | ||
|
||
// Hydrate the signed extrinsic, submit it and await finalization. | ||
const hash = await SignedExtrinsicRune | ||
.fromHex(chain, hex) | ||
.sent() | ||
.dbgStatus("Tx status:") | ||
.finalized() | ||
.run() | ||
|
||
// Ensure the extrinsic has been finalized. | ||
$.assert($.str, hash) | ||
|
||
// egdoc-ignore-start | ||
// The following noop is solely for explanation. Swap this out with your | ||
// own signed-hex-representation-consuming code. | ||
function save(_hex: string) {} | ||
// egdoc-ignore-end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ dispatchable | |
dprint | ||
edgeware | ||
efinity | ||
egdoc | ||
esbenp | ||
esque | ||
extrinsics | ||
|