Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-shirts-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@substrate/light-client-extension-helpers": patch
---

add docs for tx-helper
43 changes: 42 additions & 1 deletion packages/light-client-extension-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,45 @@ client.supervise()

### tx-helper

TODO: write usage guide
The tx-helper package allows you to easily sign transactions. You just need the calldata and an implementation of the
`@polkadot-api/signer` interface.

#### PJS Example Implementation

```ts
import { getLightClientProvider } from "@substrate/light-client-extension-helpers/web-page"
import { connectInjectedExtension } from "@polkadot-api/pjs-signer"
import { fromHex, toHex } from "@polkadot-api/utils"
import { createTx } from "@substrate/light-client-extension-helpers/tx-helper" // 👈 create-tx import

const CHANNEL_ID = "..."
const lightClientProvider = await getLightClientProvider(CHANNEL_ID)

const createTx = async (chainId: string, from: string, callData: string) => {
const chains = Object.values(lightClientProvider.getChains())
const chain = chains.find(({ genesisHash }) => genesisHash === chainId)

if (!chain) {
throw new Error("unknown chain")
}

const injectedExt = await connectInjectedExtension("polkadot-js")

const account = injectedExt
.getAccounts()
.find((account) => toHex(account.polkadotSigner.publicKey) === from)

if (!account) {
throw new Error("no account")
}

const signer = account.polkadotSigner // 👈 @polkadot-api/signer implementation

const tx = await createTx(chain.connect)({
callData: fromHex(callData),
signer,
})

return toHex(tx)
}
```