File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
packages/light-client-extension-helpers Expand file tree Collapse file tree 2 files changed +43
-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 @@ -211,4 +211,41 @@ client.supervise()
211
211
212
212
### tx-helper
213
213
214
- TODO: write usage guide
214
+ The tx-helper package allows you to easily sign transactions. You just need to calldata and an implementation of the
215
+ ` @polkadot-api/signer ` interface.
216
+
217
+ #### PJS Example Implementation
218
+
219
+ ``` ts
220
+ import { getLightClientProvider } from ' @substrate/light-client-extension-helpers/web-page' ;
221
+ import { connectInjectedExtension } from ' @polkadot-api/pjs-signer' ;
222
+ import { fromHex , toHex } from ' @polkadot-api/utils' ;
223
+ import { createTx } from ' @substrate/light-client-extension-helpers/tx-helper' ; // 👈 create-tx import
224
+
225
+ const CHANNEL_ID = " ..."
226
+ const lightClientProvider = await getLightClientProvider (CHANNEL_ID )
227
+
228
+ const createTx = async (chainId : string , from : string , callData : string ) => {
229
+ const chains = Object .values (lightClientProvider .getChains ());
230
+ const chain = chains .find (({ genesisHash }) => genesisHash === chainId );
231
+
232
+ if (! chain ) {
233
+ throw new Error (' unknown chain' );
234
+ }
235
+
236
+ const injectedExt = await connectInjectedExtension (' polkadot-js' );
237
+
238
+ const account = injectedExt .getAccounts ()
239
+ .find ((account ) => toHex (account .polkadotSigner .publicKey ) === from );
240
+
241
+ if (! account ) {
242
+ throw new Error (' no account' );
243
+ }
244
+
245
+ const signer = account .polkadotSigner ; // 👈 @polkadot-api/signer implementation
246
+
247
+ const tx = await createTx (chain .connect )({ callData: fromHex (callData ), signer });
248
+
249
+ return toHex (tx );
250
+ }
251
+ ```
You can’t perform that action at this time.
0 commit comments