-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters