Skip to content

Send event to nostr with data of APIs. Easly access and don't disturbe to APIs multiples times.

License

Notifications You must be signed in to change notification settings

rapax00/nostr-oracle

Repository files navigation

Nostr Oracle

License Stars Forks

Send event to nostr with data of APIs. Easly access and don't disturbe to APIs multiples times.

Table of Contents

Flow

Oracle

  1. Oracle get data from APIs.
  2. Oracle create event with the data and publish to Nostr each X time.

You

  1. You subscribe with a filter to Nostr.
  2. You get the data from the event and use it.

Nostr Oracle Flow

Configuration

1. Setup environment variables

Copy .env.example to .env and fill the NOSTR_PRIVATE_KEY with random private key for sign events

The public key is used to filter events.

cp .env.example .env

2. Setup

Use correct node version

nvm use

Install the dependencies

pnpm i

3. Run in dev mode

pnpm dev

Data Events

Are two types of events:

  • Remplazable data: are parameterized replaceable, the relay must save the last event with the last update of the oracle. The oracle updates these events in a short period of time. For example: every 1 minute.
  • Historical data (WIP): are regular, the relay save all events. The oracle updates these events in a long period of time. For example: every 1 hour.

Remplazable data event

{
    "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <32-bytes lowercase hex-encoded public key of the oracle>,
  "created_at": <unix timestamp in seconds>,
  "kind": 30021,
  "tags": [
      [
          "d",
        <string, information of the event data>
    ]
  ],
  "content": <string JSON enconde, data>,
  "sig":  <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data>
}

KIND: 30021, parameterized replaceable event. More info in NIP-01.

D Tags

btc:price

  • About: Bitcoin price in USD from yadio.io.

  • Content:

    "price": "<string>"

btc:height (WIP)

  • About: Bitcoin block height.
  • Content:

btc:fee (WIP)

  • About: Bitcoin fees in satoshi per byte.
  • Content:

btc:difficulty (WIP)

  • About: Bitcoin mining difficulty.
  • Content:

Historical data event (WIP)

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <32-bytes lowercase hex-encoded public key of the oracle>,
  "created_at": <unix timestamp in seconds>,
  "kind": 3021,
  "tags": [
    [
        "d",
        <string, information of the event data>
    ]
  ],
  "content": <string JSON enconde, data>,
  "sig":  <64-bytes lowercase hex of the signature of the sha256 hash of the serialized event data>
}

KIND: 3021, regular event. More info in NIP-01.

To Do

  • Function to get data from APIs
  • Function to create event
  • Function to send event to Nostr
  • Improve README
    • Filter examples
  • Use nostr-tools for conect to relays
  • Fix conection to multiple relays
  • Historical events (regular nostr events)
  • Other data events

Ideas for names:

  • Noracle
  • Nostracle

Made with 👐 by Rapax

Tips are welcome through Lightning Zap to ⚡rapax@lawallet.ar.

About

Send event to nostr with data of APIs. Easly access and don't disturbe to APIs multiples times.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published