Skip to content

Commit

Permalink
feat: add apis
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed May 15, 2024
1 parent e595b0c commit ce4fcc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/pages/typed/apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Runtime APIs

Runtime APIs (aka Runtime calls in other frameworks) directly query the wasm runtime to get some information. In PAPI they're under `typedApi.apis`. Let's see its interface:

```ts
type CallOptions = Partial<{
at: string
signal: AbortSignal
}>
interface RuntimeCall<Args, Payload> {
(...args: [...Args, options?: CallOptions]): Promise<Payload>
isCompatible: IsCompatible
}
```

They're fairly straight-forward, let's see it with some examples:

With `callOptions.at` we can control which block to query. It can be a blockHash, `"finalized"` (the default), or `"best"`

```ts
// there are some APIs that do not take arguments!
const metadata = await typedApi.apis.Metadata.metadata()

// we can pass as well callOptions
const metadataAtBest = await typedApi.apis.Metadata.metadata({ at: "best" })

// this one takes a number as argument
const metadataV15 = await typedApi.apis.Metadata.metadata_at_version(15, {
at: "best",
})
```
4 changes: 4 additions & 0 deletions vocs.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default defineConfig({
text: "Constants",
link: "/typed/constants",
},
{
text: "Runtime APIs",
link: "/typed/apis",
},
{
text: "Storage queries",
link: "/typed/queries",
Expand Down

0 comments on commit ce4fcc6

Please sign in to comment.