You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`getTypedApi` has nearly no cost at runtime, so it can be safely called many times.
122
122
:::
123
+
124
+
## Whitelist
125
+
126
+
In order to reduce the size of PAPI descriptors bundle, one could filter which calls, queries, etc wants to use and ship with the dApp. This part is particularly interesting when developing web-based dApps, rather than NodeJS or Desktop apps, where bundle size is less critical.
127
+
128
+
In order to enable the whitelist feature of the codegen, one has to write a `whitelist.ts` file that our CLI can understand. The shape is as follows:
129
+
130
+
```ts
131
+
import { DotWhitelistEntry } from "@polkadot-api/descriptors"
132
+
133
+
const dotWhitelist: DotWhitelistEntry[] = [
134
+
// this will get all calls, queries, and consts inside Balances pallet
135
+
"*.Balances",
136
+
137
+
// this just a specific tx
138
+
"tx.XcmPallet.transfer_assets",
139
+
140
+
// all queries inside system pallet
141
+
"query.System.*",
142
+
143
+
// all constants
144
+
"const.*",
145
+
]
146
+
147
+
// the export name has to *EXACTLY* match `whitelist`
148
+
export const whitelist = [...dotWhitelist]
149
+
```
150
+
151
+
If you generated descriptors forkey `dot` (or any other `key` you used to generate the descriptors) you will have that `<Key>WhitelistEntry` helper type that will provide type checking for your whitelist. You can explore all options that you can choosein your IDE. Of course, this can be multichain, let's see an example of it (for `dot` and `dotAh` descriptor keys).
This file could be placed anywhere, but we recommend placing it at `.papi/whitelist.ts`.
167
+
168
+
In order to generate descriptors taking into account the whitelist, the command should be `papi generate --whitelist .papi/whitelist.ts` (or just `papi --whitelist .papi/whitelist.ts`), or any other directory you chose to save your file. We recommend setting a script in your `package.json` that takes care of it.
169
+
170
+
A full working example of a dApp with whitelist could be found at [our repo](https://github.com/polkadot-api/polkadot-api/tree/main/examples/vite).
0 commit comments