File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
packages/light-client-extension-helpers Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @substrate/light-client-extension-helpers " : patch
3
+ ---
4
+
5
+ add docs for tx-helper
Original file line number Diff line number Diff line change @@ -225,4 +225,45 @@ client.supervise()
225
225
226
226
### tx-helper
227
227
228
- TODO: write usage guide
228
+ The tx-helper package allows you to easily sign transactions. You just need the calldata and an implementation of the
229
+ ` @polkadot-api/signer ` interface.
230
+
231
+ #### PJS Example Implementation
232
+
233
+ ``` ts
234
+ import { getLightClientProvider } from " @substrate/light-client-extension-helpers/web-page"
235
+ import { connectInjectedExtension } from " @polkadot-api/pjs-signer"
236
+ import { fromHex , toHex } from " @polkadot-api/utils"
237
+ import { createTx } from " @substrate/light-client-extension-helpers/tx-helper" // 👈 create-tx import
238
+
239
+ const CHANNEL_ID = " ..."
240
+ const lightClientProvider = await getLightClientProvider (CHANNEL_ID )
241
+
242
+ const createTx = async (chainId : string , from : string , callData : string ) => {
243
+ const chains = Object .values (lightClientProvider .getChains ())
244
+ const chain = chains .find (({ genesisHash }) => genesisHash === chainId )
245
+
246
+ if (! chain ) {
247
+ throw new Error (" unknown chain" )
248
+ }
249
+
250
+ const injectedExt = await connectInjectedExtension (" polkadot-js" )
251
+
252
+ const account = injectedExt
253
+ .getAccounts ()
254
+ .find ((account ) => toHex (account .polkadotSigner .publicKey ) === from )
255
+
256
+ if (! account ) {
257
+ throw new Error (" no account" )
258
+ }
259
+
260
+ const signer = account .polkadotSigner // 👈 @polkadot-api/signer implementation
261
+
262
+ const tx = await createTx (chain .connect )({
263
+ callData: fromHex (callData ),
264
+ signer ,
265
+ })
266
+
267
+ return toHex (tx )
268
+ }
269
+ ```
You can’t perform that action at this time.
0 commit comments