diff --git a/docs/components/KeyPoint.tsx b/docs/components/KeyPoint.tsx index 7d2b85da..63a084ee 100644 --- a/docs/components/KeyPoint.tsx +++ b/docs/components/KeyPoint.tsx @@ -1,4 +1,4 @@ -import { FC, PropsWithChildren } from "react"; +import { FC, PropsWithChildren } from "react" export const KeyPoint: FC> = ({ title, @@ -10,4 +10,4 @@ export const KeyPoint: FC> = ({
{children}
-); +) diff --git a/docs/components/Tabs.css b/docs/components/Tabs.css index a385df56..a20ad78f 100644 --- a/docs/components/Tabs.css +++ b/docs/components/Tabs.css @@ -1,15 +1,14 @@ - @media screen and (max-width: 720px) { .Tabs__root { border-radius: 0; - margin-left: calc(-1* var(--vocs-space_16)); - margin-right: calc(-1* var(--vocs-space_16)); + margin-left: calc(-1 * var(--vocs-space_16)); + margin-right: calc(-1 * var(--vocs-space_16)); padding-left: var(--vocs-space_16); padding-right: var(--vocs-space_16); } .Tabs__list { - margin-left: calc(-1* var(--vocs-space_16)); - margin-right: calc(-1* var(--vocs-space_16)); + margin-left: calc(-1 * var(--vocs-space_16)); + margin-right: calc(-1 * var(--vocs-space_16)); } -} \ No newline at end of file +} diff --git a/docs/components/Tabs.tsx b/docs/components/Tabs.tsx index b02717a4..ed18a0d2 100644 --- a/docs/components/Tabs.tsx +++ b/docs/components/Tabs.tsx @@ -1,12 +1,12 @@ -import * as Tabs from "@radix-ui/react-tabs"; -import { PropsWithChildren } from "react"; -import "./Tabs.css"; +import * as Tabs from "@radix-ui/react-tabs" +import { PropsWithChildren } from "react" +import "./Tabs.css" export const Root = ({ options, children, }: PropsWithChildren<{ - options: Record; + options: Record }>) => ( {children} -); +) export const Content = (props: Tabs.TabsContentProps) => ( -); +) diff --git a/docs/pages/codegen.md b/docs/pages/codegen.md index bb16f4f9..e822421e 100644 --- a/docs/pages/codegen.md +++ b/docs/pages/codegen.md @@ -85,35 +85,29 @@ import { XcmVersionedXcm, XcmV2Instruction, XcmV2MultilocationJunctions, -} from '@polkadot-api/descriptors'; +} from "@polkadot-api/descriptors" // ... -const dotClient = createClient( - scProvider(WellKnownChain.polkadot).relayChain -) -const ksmClient = createClient( - scProvider(WellKnownChain.ksmcc3).relayChain -) +const dotClient = createClient(scProvider(WellKnownChain.polkadot).relayChain) +const ksmClient = createClient(scProvider(WellKnownChain.ksmcc3).relayChain) -const dotApi = dotClient.getTypedApi(dot); -const ksmApi = ksmClient.getTypedApi(ksm); +const dotApi = dotClient.getTypedApi(dot) +const ksmApi = ksmClient.getTypedApi(ksm) const xcmSendTx = dotApi.tx.XcmPallet.send({ dest: XcmVersionedMultiLocation.V2({ parents: 0, interior: XcmV2MultilocationJunctions.Here(), }), - message: XcmVersionedXcm.V2([ - XcmV2Instruction.ClearOrigin() - ]), -}); + message: XcmVersionedXcm.V2([XcmV2Instruction.ClearOrigin()]), +}) -const encodedData = await xcmSendTx.getEncodedData(); +const encodedData = await xcmSendTx.getEncodedData() -const finalizedCall = await xcmSendTx.signAndSubmit(signer); +const finalizedCall = await xcmSendTx.signAndSubmit(signer) ``` :::info `getTypedApi` has nearly no cost at runtime, so it can be safely called many times. -::: \ No newline at end of file +::: diff --git a/docs/pages/getting-started.mdx b/docs/pages/getting-started.mdx index ecd454b6..b28d63f9 100644 --- a/docs/pages/getting-started.mdx +++ b/docs/pages/getting-started.mdx @@ -1,4 +1,4 @@ -import * as Tabs from '../components/Tabs'; +import * as Tabs from "../components/Tabs" # Getting Started @@ -49,6 +49,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int // [!include ~/snippets/gettingStarted.ts:usage] ``` + ```ts @@ -67,6 +68,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int // [!include ~/snippets/gettingStarted.ts:usage] ``` + ```ts @@ -80,6 +82,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int // [!include ~/snippets/gettingStarted.ts:usage] ``` + ```ts @@ -93,5 +96,6 @@ Now you can create a PolkadotClient with a provider of your choice and start int // [!include ~/snippets/gettingStarted.ts:usage] ``` + diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index febc6296..b45fe414 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -1,11 +1,11 @@ --- layout: landing -content: +content: width: 60rem --- -import { HomePage } from 'vocs/components' -import { KeyPoint } from '../components/KeyPoint'; +import { HomePage } from "vocs/components" +import { KeyPoint } from "../components/KeyPoint"
@@ -19,6 +19,7 @@ import { KeyPoint } from '../components/KeyPoint';
+
@@ -47,5 +48,6 @@ import { KeyPoint } from '../components/KeyPoint'; - ✨ **Promise-based and Observable-based APIs**: use the one that best suit your needs and/or coding style. - 🔑 Use **signers** from your browser extension, or from a private key. - 🧩 Easy integration with **PJS-based extensions**. +
-
\ No newline at end of file + diff --git a/docs/pages/providers.md b/docs/pages/providers.md index 5c504ee4..18a3d81a 100644 --- a/docs/pages/providers.md +++ b/docs/pages/providers.md @@ -28,25 +28,25 @@ Polkadot-API has a subpackage `polkadot-api/logs-provider` that can be used to c ```ts // 1. recording logs -import { createClient } from 'polkadot-api'; -import { withLogsRecorder } from 'polkadot-api/logs-provider'; -import { WebSocketProvider } from 'polkadot-api/ws-provider/node'; +import { createClient } from "polkadot-api" +import { withLogsRecorder } from "polkadot-api/logs-provider" +import { WebSocketProvider } from "polkadot-api/ws-provider/node" -const wsProvider = WebSocketProvider("wss://example.url"); +const wsProvider = WebSocketProvider("wss://example.url") // Using console.log to output each line, but you could e.g. write it directly to a // file or push into an array -const provider = withLogsRecorder(line => console.log(line), wsProvider); -const client = createClient(provider); +const provider = withLogsRecorder((line) => console.log(line), wsProvider) +const client = createClient(provider) ``` ```ts // 2. replaying logs -import { createClient } from 'polkadot-api'; -import { logsProvider } from 'polkadot-api/logs-provider'; -import logs from './readLogs'; +import { createClient } from "polkadot-api" +import { logsProvider } from "polkadot-api/logs-provider" +import logs from "./readLogs" -const provider = logsProvider(logs); -const client = createClient(provider); +const provider = logsProvider(logs) +const client = createClient(provider) ``` This can be useful to debug specific scenarios without needing to depend on an external source. diff --git a/docs/pages/recipes/upgrade.md b/docs/pages/recipes/upgrade.md index 6fa5f094..c0eb1514 100644 --- a/docs/pages/recipes/upgrade.md +++ b/docs/pages/recipes/upgrade.md @@ -24,31 +24,31 @@ Now on the code you can create two typed APIs for the same chain, and then use t To make it clear, the `client` is connected to one chain that's using one specific version of the runtime. You can create multiple typedApis for that connection, which just give you the types for each possible version of the runtime. Then you can use runtime compatibility checks to perform the operation on the correct descriptor. ```ts -import { createClient } from 'polkadot-api'; -import { dot, nextDot, MultiAddress } from '@polkadot-api/descriptors'; -import { chainSpec } from "polkadot-api/chains/polkadot"; -import { startFromWorker } from "polkadot-api/smoldot/from-worker"; -import SmWorker from "polkadot-api/smoldot/worker?worker"; +import { createClient } from "polkadot-api" +import { dot, nextDot, MultiAddress } from "@polkadot-api/descriptors" +import { chainSpec } from "polkadot-api/chains/polkadot" +import { startFromWorker } from "polkadot-api/smoldot/from-worker" +import SmWorker from "polkadot-api/smoldot/worker?worker" -const smoldot = startFromWorker(new SmWorker()); -const chain = await smoldot.addChain({ chainSpec }); -const client = createClient(getSmProvider(chain)); +const smoldot = startFromWorker(new SmWorker()) +const chain = await smoldot.addChain({ chainSpec }) +const client = createClient(getSmProvider(chain)) -const dotApi = client.getTypedApi(dot); -const nextApi = client.getTypedApi(nextDot); +const dotApi = client.getTypedApi(dot) +const nextApi = client.getTypedApi(nextDot) function performTransfer() { // check if we're running on the next version to run that first if (await nextApi.tx.Balances.new_fancy_transfer.isCompatible()) { nextApi.tx.Balances.new_fancy_transfer({ dest: MultiAddress.Id("addr"), - value: 5n + value: 5n, }) } else { // Otherwise perform the transfer the old way with the old descriptors dotApi.tx.Balances.transfer_keep_alive({ dest: MultiAddress.Id("addr"), - value: 5n + value: 5n, }) } } diff --git a/docs/pages/signers.md b/docs/pages/signers.md index aa9813bf..d1ac00f5 100644 --- a/docs/pages/signers.md +++ b/docs/pages/signers.md @@ -31,19 +31,24 @@ This interface is generic to signing transactions for the chain. If you want to use a compatible extension as a signer, Polkadot-API has a subpath with a couple of utilities to help with this: `polkadot-api/pjs-signer`. ```ts -import { getInjectedExtensions, connectInjectedExtension } from 'polkadot-api/pjs-signer'; +import { + getInjectedExtensions, + connectInjectedExtension, +} from "polkadot-api/pjs-signer" // Get the list of installed extensions -const extensions: string[] = getInjectedExtensions(); +const extensions: string[] = getInjectedExtensions() // Connect to an extension -const selectedExtension: InjectedExtension = await connectInjectedExtension(extensions[0]); +const selectedExtension: InjectedExtension = await connectInjectedExtension( + extensions[0], +) // Get accounts registered in the extension -const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts(); +const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts() // The signer for each account is in the `polkadotSigner` property of `InjectedPolkadotAccount` -const polkadotSigner = accounts[0].polkadotSigner; +const polkadotSigner = accounts[0].polkadotSigner ``` ## `PolkadotSigner` from generic signing function @@ -75,11 +80,8 @@ const derive = sr25519CreateDerive(miniSecret) const keypair = derive("//Alice") const polkadotSigner = getPolkadotSigner( - hdkdKeyPair.publicKey, - "Sr25519", - hdkdKeyPair.sign -); + hdkdKeyPair.publicKey, + "Sr25519", + hdkdKeyPair.sign, +) ``` - - - diff --git a/docs/pages/types.mdx b/docs/pages/types.mdx index 962a5401..853789c5 100644 --- a/docs/pages/types.mdx +++ b/docs/pages/types.mdx @@ -11,14 +11,14 @@ Binary values tagged as a accounts are abstracted as `SS58String`. The type `SS5 When PolkadotAPI receives an `SS58String` as a parameter, it can be in any valid format. But the `SS58String` returned from any of the methods will always be in the format declared by the chain's metadata. ```ts -const dotApi = client.getTypedApi(dot); +const dotApi = client.getTypedApi(dot) const [proxies, deposit] = await dotApi.query.Proxy.Proxies.getValue( // HDX format (for demo purposes that it accepts any SS58 string, regardless of the chain) - "7LE64AxmGixNsxFs1rdsDkER5nuuQ28MbrSS7JtHwRmdcdam" -); + "7LE64AxmGixNsxFs1rdsDkER5nuuQ28MbrSS7JtHwRmdcdam", +) -console.log(proxies[0].delegate); +console.log(proxies[0].delegate) // "12R1XCdgkHysv8Y4ntiXguo4eUYHXjQTmfRjL8FbmezsG71j", which is polkadot's format ``` @@ -26,7 +26,6 @@ console.log(proxies[0].delegate); Another alias of `string`, but indicates that the value is a valid hexadecimal string. It accepts the string with or without the `0x` prefix, but `HexString` returned from methods always have `0x`. - ## Enum Enums in the chain are represented as `{ type: string, value: T }`. As many of the types have nested enums that would make it hard to work with (both creating these types and also reading them), Polkadot-API helps through a set of utilites. @@ -64,10 +63,10 @@ For these cases, you should use the function `Enum(type, value)`, imported from ```ts dotApi.apis.TransactionPaymentCallApi.query_call_info( PolkadotRuntimeRuntimeCall.Balances( - Enum("transfer_allow_death", { dest: MultiAddress.Id(address), value: 3n }) + Enum("transfer_allow_death", { dest: MultiAddress.Id(address), value: 3n }), ), - 10 -); + 10, +) ``` When reading from Enums, these are objects with `{ type: string, value: unknown }` with discriminated types based on the `type` (so if you do `switch (enum.type) {` you will have the correct value for the `type`). @@ -81,10 +80,9 @@ Binary.fromBytes(new Uint8Array()) Binary.fromHex("0b187a23c4f65d86c9a324b56f7e81aa") const binary = Binary.fromText("Text that will be turned into binary") -binary.asBytes(); // Uint8Array -binary.asHex(); // "0x5465787420746861742077696c6c206265207475726e656420696e746f2062696e617279" -binary.asText(); // "Text that will be turned into binary" - +binary.asBytes() // Uint8Array +binary.asHex() // "0x5465787420746861742077696c6c206265207475726e656420696e746f2062696e617279" +binary.asText() // "Text that will be turned into binary" ``` ## FixedSizeBinary<L> @@ -107,43 +105,41 @@ import { DotConstants, DotErrors, DotEvents, -} from "@polkadot-api/descriptors"; +} from "@polkadot-api/descriptors" // Storage queries function processAccount(account: DotQueries["System"]["Account"]["Value"]) { // ... } -processAccount(await dotApi.query.System.Account.getValue("SS58Account")); +processAccount(await dotApi.query.System.Account.getValue("SS58Account")) // Constants function formatSS58Account( value: DotConstants["System"]["SS58Prefix"], - account: Uint8Array + account: Uint8Array, ) { // ... } -formatSS58Account(await dotApi.constants.System.SS58Prefix(), new Uint8Array()); +formatSS58Account(await dotApi.constants.System.SS58Prefix(), new Uint8Array()) // Transactions function performTransfer( - transfer: DotCalls["Balances"]["transfer_allow_death"] + transfer: DotCalls["Balances"]["transfer_allow_death"], ) { - return dotApi.tx.Balances.transfer_allow_death(transfer).signAndSubmit( - signer - ); + return dotApi.tx.Balances.transfer_allow_death(transfer).signAndSubmit(signer) } performTransfer({ dest: MultiAddress.Id("SS58Account"), value: 100n, -}); +}) // Events -function reactToNewAccount(event: DotEvents['System']['NewAccount']) { +function reactToNewAccount(event: DotEvents["System"]["NewAccount"]) { // ... } // Errors -function logError(error: DotErrors['System']['InvalidSpecName']) { +function logError(error: DotErrors["System"]["InvalidSpecName"]) { // ... } ``` diff --git a/docs/snippets/gettingStarted.ts b/docs/snippets/gettingStarted.ts index aca9067b..0d550b4e 100644 --- a/docs/snippets/gettingStarted.ts +++ b/docs/snippets/gettingStarted.ts @@ -1,22 +1,22 @@ // [!region import] // `dot` is the name we gave to `npx papi add` -import { dot } from "@polkadot-api/descriptors"; -import { createClient } from "polkadot-api"; +import { dot } from "@polkadot-api/descriptors" +import { createClient } from "polkadot-api" // [!endregion import] // [!region usage] // With the `client`, you can get information such as subscribing to the last // block to get the latest hash: client.finalized$.subscribe((finalizedBlock) => - console.log(finalizedBlock.number, finalizedBlock.hash) -); + console.log(finalizedBlock.number, finalizedBlock.hash), +) // To interact with the chain, you need to get the `TypedApi`, which includes // all the types for every call in that chain: -const dotApi = client.getTypedApi(dot); +const dotApi = client.getTypedApi(dot) // get the value for an account const accountInfo = await dotApi.query.System.Account.getValue( - "16JGzEsi8gcySKjpmxHVrkLTHdFHodRepEz8n244gNZpr9J" -); + "16JGzEsi8gcySKjpmxHVrkLTHdFHodRepEz8n244gNZpr9J", +) // [!endregion usage] diff --git a/docs/styles.css b/docs/styles.css index 98a3263c..394bd250 100644 --- a/docs/styles.css +++ b/docs/styles.css @@ -1,3 +1,5 @@ -@layer vocs_preflight { @tailwind base; } +@layer vocs_preflight { + @tailwind base; +} @tailwind components; @tailwind utilities;