> For the complete documentation index, see [llms.txt](https://zapproject.gitbook.io/zapproject/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zapproject.gitbook.io/zapproject/oracles/creating-first-oracle/subscription-oracle-template.md).

# Subscription-Oracle Template

### Introduction

Subscription oracle template serves as bootstrap tool for data provider to setup and run their service in minutes.&#x20;

**Purpose** : to provide a subscription service based on Zap oracle platform to manage subscriptions and distribute information through authenticated websocket connections.

### Work flow

*This workflow has been provided in the template , following information explains how things works within source code*

***ORACLE***

{% tabs %}
{% tab title="Requirements" %}

* Oracle is registered and created an endpoint with curve set for a subscription service (not to be queried)&#x20;
* Node/Yarn installed
* Modify [Config.ts](https://github.com/zapproject/websocket-oracle-template/blob/master/src/config.ts) with your custom information such as Mnemonic and optional custom URL for parity node ( default to infura)
* Method[ `getData`](https://github.com/zapproject/websocket-oracle-template/blob/master/src/server.ts#L66) needs to be implemented to get data from database or other source and emit data to authenticated connections,
  {% endtab %}

{% tab title="How it works" %}

* Oracle creates authenticated websocket server
* Oracle run `yarn server` which will start listening to connections, verify user and emitting data to connected users
  {% endtab %}
  {% endtabs %}

{% hint style="info" %}
Dont have Oracle and Endpoint registered ? You can easily do so in couple provided tools:

* [Zap Admin](/zapproject/tools/zap-admin.md)
* [Zap-term](/zapproject/tools/zap-term.md)

Integrate into your application  :

[@zapjs/provider](https://github.com/zapproject/zap-monorepo/tree/master/packages/Provider)
{% endhint %}

***USER***

*This template also includes bootstrap for user to use their Ethereum address to authenticate and connect to receive data from this type of subscription Oracle's endpoint.*

{% tabs %}
{% tab title="Requirements" %}

* User approve -> bond -> subscribe to Oracle's endpoint
  {% endtab %}

{% tab title="How it works" %}

* User connect to server websocket with params:
  * {
  * signature: {{sign endpoint's name with user's address}},
  * endpoint: {{endpoint name}},
  * address: {{user's address}}
  * }
* After successful authenticated, user will be able to connect with websocket until the block remaining subscriptions is 0
* User listen to channel `signalData` from Oracle and receive data
  {% endtab %}
  {% endtabs %}

{% hint style="info" %}
Use our tools to easily approve, bond, subscribe to Oracles Endpoint

UI /Terminal&#x20;

* [Zap Admin](/zapproject/tools/zap-admin.md)
* [Zap-term](/zapproject/tools/zap-term.md)

Integrate into your application :&#x20;

* [@zapjs/subscriber](https://github.com/zapproject/zap-monorepo/tree/master/packages/Subscriber)
  {% endhint %}

### Setup

* **`yarn`**
* Create `priv_config.ts` based on `config.ts` template with oracle's information
* In `src/server.ts` modify method `getData` to get custom data of your own. This data will be broadcasted to users

#### **Run Server:**

* &#x20;**`yarn server`**

#### **User Connecting to server:**

* In `src/user.ts` modify signature, address and endpoint
* **`yarn user`**

### [Source Code](https://github.com/zapproject/websocket-oracle-template)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zapproject.gitbook.io/zapproject/oracles/creating-first-oracle/subscription-oracle-template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
