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
3 changes: 3 additions & 0 deletions .papi/descriptors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!package.json
24 changes: 24 additions & 0 deletions .papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.1.0-autogenerated.12133326621938921434",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"browser": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
"peerDependencies": {
"polkadot-api": ">=1.11.2"
}
}
Binary file added .papi/metadata/dot.scale
Binary file not shown.
12 changes: 12 additions & 0 deletions .papi/polkadot-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 0,
"descriptorPath": ".papi/descriptors",
"entries": {
"dot": {
"chain": "polkadot",
"metadata": ".papi/metadata/dot.scale",
"genesis": "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
"codeHash": "0xa4d527cb0db4146686eeffb216b562fe68440185d5067e6177d1681ff7bb3043"
}
}
}
32 changes: 9 additions & 23 deletions docs/pages/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,24 @@ Now you can create a `PolkadotClient` instance with a [provider](/providers) of

:::code-group

```typescript [Smoldot]
```typescript twoslash [Smoldot]
// [!include ~/snippets/gettingStarted.ts:import]
import { getSmProvider } from "polkadot-api/sm-provider"
import { chainSpec } from "polkadot-api/chains/polkadot"
import { start } from "polkadot-api/smoldot"

// if interested, check out how to create a smoldot instance in a WebWorker
// http://papi.how/providers/sm#webworker
const smoldot = start()
const chain = await smoldot.addChain({ chainSpec })

// Connect to the polkadot relay chain.
const client = createClient(getSmProvider(chain))
// [!include ~/snippets/gettingStarted.ts:smoldot]
```

```typescript [WebSocket]
```typescript twoslash [WebSocket]
// [!include ~/snippets/gettingStarted.ts:import]
import { getWsProvider } from "polkadot-api/ws-provider"
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"

// Connect to the polkadot relay chain.
const client = createClient(
// Polkadot-SDK Nodes have issues, see the documentation for more info
// on this enhancer https://papi.how/providers/enhancers#polkadot-sdk-compatibility-layer
withPolkadotSdkCompat(getWsProvider("wss://dot-rpc.stakeworld.io")),
)
// [!include ~/snippets/gettingStarted.ts:websocket]
```

:::

### 2. Start consuming the client!

```typescript
```typescript twoslash
// [!include ~/snippets/gettingStarted.ts:import]
// [!include ~/snippets/gettingStarted.ts:smoldot]

// ---cut---
// [!include ~/snippets/gettingStarted.ts:usage]
```
2 changes: 1 addition & 1 deletion docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { KeyPoint } from "../components/KeyPoint"
</div>

<div className="text-left w-full max-w-5xl p-2">
<h2 className="text-(--vocs-color_heading) text-3xl py-4 border-b border-gray-500 mb-4">Features</h2>
<h2 className="text-(--vocs-color_heading) text-3xl py-4 mb-4">Features</h2>

- 🪶 **Light client first**: built on top of the [new JSON-RPC spec](https://paritytech.github.io/json-rpc-interface-spec/) to fully leverage the potential of light-clients.
- 💡 Delightful **TypeScript support** with types and docs generated from on-chain metadata.
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/providers/enhancers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

If using Polkadot-API client through Smoldot provider (light client) there are no specific requirements.

Nevertheless, some [WS Providers](./ws) over a [Paritytech Polkadot-SDK](https://github.com/paritytech/polkadot-sdk) based node offer a flawed version of the JSON-RPC API Spec, which can be solved in the client in some cases.
Nevertheless, some [WS Providers](/providers/ws) over a [Paritytech Polkadot-SDK](https://github.com/paritytech/polkadot-sdk) based node offer a flawed version of the JSON-RPC API Spec, which can be solved in the client in some cases.

:::warning
If you are using [`@polkadot-api/legacy-provider`](./enhancers#legacy), **DO NOT** use `withPolkadotSdkCompat`. `withLegacy` already tackles every bit to offer a spec compliant JSON-RPC server.
If you are using [`@polkadot-api/legacy-provider`](/providers/enhancers#legacy-provider), **DO NOT** use `withPolkadotSdkCompat`. `withLegacy` already tackles every bit to offer a spec compliant JSON-RPC server.
:::

Our recommendation is to **always use** `withPolkadotSdkCompat` to avoid any issues, but there are three cases:
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/providers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Besides providers, we offer some enhancers (aka middlewares) for JSON-RPC provid

- [Polkadot-SDK Compatibility Enhancer](/providers/enhancers#polkadot-sdk-compatibility-layer), fixing common pitfalls among JSON-RPC servers running over Polkadot-SDK nodes.
- [Legacy Provider](/providers/enhancers#legacy-provider), a compliant middleware that exposes the modern [JSON-RPC APIs](https://paritytech.github.io/json-rpc-interface-spec/) while delegating calls to the legacy JSON-RPC APIs.
- [Logs Provider and Recorder](./enhancers#logs-provider), allowing to capture JSON-RPC messaging logs, useful for debugging and/or analytics.
- [Logs Provider and Recorder](/providers/enhancers#logs-provider), allowing to capture JSON-RPC messaging logs, useful for debugging and/or analytics.

## JSON-RPC providers in-depth

Expand Down
32 changes: 15 additions & 17 deletions docs/pages/providers/sm.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,37 @@ Once we have an instance of smoldot, we need to tell smoldot to connect to the c

In order to add a solo-chain (or a relay chain), it is very simple:

```ts
```ts twoslash
// [!include ~/snippets/startSm.ts]
// ---cut---
import { chainSpec } from "polkadot-api/chains/polkadot"

const polkadotChain: Promise<Chain> = smoldot.addChain({ chainSpec })
const polkadotChain = smoldot.addChain({ chainSpec })
// ^?
```

In case it is a parachain, we will need both the `chainSpec` of the relay chain, and the parachain one. It is simple as well:

```ts
```ts twoslash
// [!include ~/snippets/startSm.ts]
// ---cut---
import { polkadot, polkadot_asset_hub } from "polkadot-api/chains"

// without async-await
const assetHubChain: Promise<Chain> = smoldot
.addChain({ chainSpec: polkadot })
.then((relayChain) =>
smoldot.addChain({
chainSpec: polkadot_asset_hub,
potentialRelayChains: [relayChain],
}),
)

// or with an async-await structure:
const assetHubChain: Promise<Chain> = smoldot.addChain({
const relayChain = await smoldot.addChain({ chainSpec: polkadot })
const assetHubChain = smoldot.addChain({
chainSpec: polkadot_asset_hub,
potentialRelayChains: [await smoldot.addChain({ chainSpec: polkadot })],
potentialRelayChains: [relayChain],
})
```

## Getting the provider and initializing the client

Once we have a `Chain` (or `Promise<Chain>`), we can initialize the provider and the client.

```ts
```ts twoslash
// [!include ~/snippets/startSm.ts]
// ---cut---
import { chainSpec } from "polkadot-api/chains/polkadot"
import { createClient } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"

Expand Down
191 changes: 0 additions & 191 deletions docs/pages/signers.md

This file was deleted.

Loading