Skip to content

Commit

Permalink
Add applyParameters to JS sink (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
enoldev authored Feb 25, 2024
1 parent 16ca026 commit e938947
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/new/consume/stream/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,40 @@ const main = async () => {
Now, you can send the data anywhere and create your own custom sink! If you have created a sink and you think it can be reused by other developers, [let us know on Discord](https://discord.gg/jZwqxJAvRs)!

The previous code is availalble [on GitHub](https://gist.github.com/enoldev/b9f32e045f47675bd5c20f92246aed84).

### Passing Parameters

The `@substreams/core` package exposes an `applyParams(...)` function, which allows you to dynamically pass parameters to the Substreams.

```javascript
// ...imports omitted...
import { applyParams } from '@substreams/core'; // 1.

const pkg = await fetchPackage() // 2.
const registry = createRegistry(pkg);

const transport = createConnectTransport({
baseUrl: "https://mainnet.sol.streamingfast.io:443",
interceptors: [createAuthInterceptor(TOKEN)],
useBinaryFormat: true,
jsonOptions: {
typeRegistry: registry,
},
});

applyParams( // 3.
[`${MODULE}=parameter_name=parameter_value`],
pkg.modules.modules
);

// ...code omitted...

for await (const response of streamBlocks(transport, request)) { // 4.
// ...code omitted...
}
```
1. Import the `applyParams` function.
2. Download the `spkg` file and create the package abstraction.
3. Apply the parameters to the package module(s). The formart should be:
`module_name=parameter_name=parameter_value`.
4. Stream blocks.
8 changes: 8 additions & 0 deletions docs/new/references/manifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ or
network: ethereum
```

### image

The `image` field specifies the icon displayed for the Substreams package, which is used in the [Substreams Regsitry](https://substreams.dev). The path is relative to the folder where the manifest is.

```yaml
image: ./ethereum-icon.png
```

### sink

The `sink` field specifies the sink you want to use to consume your data (for example, a database or a subgraph).
Expand Down

0 comments on commit e938947

Please sign in to comment.