1.0.1 • Published 2 years ago

noracle-js v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

noracle-js

This repository hosts the source code for the Noracle Node.js package. This package allows you to:

  • Link your domain name to your Hedera blockchain address.
  • Run an on-chain data feed by directly sending data from your website to a data feed smart contract.

How to use it

Install.

npm i noracle-js

Import.

const noracle = require('noracle-js');

Setup

Set the following two environment variables.

NORACLE_HEDERA_ADDRESS
NORACLE_HEDERA_PRIVATE_KEY

Set NORACLE_HEDERA_ADDRESS to the address that you would like to link to your domain. Set NORACLE_HEDERA_PRIVATE_KEY to the private key that corresponds to that address.

When you call noracle-js functions, it will call the blockchain from the account that corresponds to these environment variables.

Note: noracle-js submits only two kinds of transactions:

  • The transaction in which you link your domain name to your address
  • Every transaction to your domain's data feed contract (which is created when you link your domain)

Link your domain and create your data feed contract

Link your domain to your Hedera address, and create a data feed contract for your domain.

Your domain is linked to your address in a two step process:

  1. Use the private key corresponding to your domain's SSL certificate to sign a message (which, in this case, is your Hedera address).
  2. Send that message to the Noracle VerifySSLCertificate smart contract. This contract verifies that the message was indeed signed by the domain's SSL certificate. It then creates a data Feed smart contract that can only be updated by the address linked to the domain name.

All of the above is accomplished with the following noracle-js function.

linkDomainToAddressAndCreateFeed(pathToCert, pathToPrivateKey);

Where pathToCert is the path to the .pem file containing your domain's SSL certificate, and pathToPrivateKey is the path to the .pem file containing the certificate's private key.

(We assume the user generated their SSL certificate with Let's Encrypt and Certbot.)

To run your data feed, you need to create a JSON file on your server that will tell noracle-js (a) what the latest value of the data feed is and (b) what the data type of your feed is. Create this file with the following noracle-js function.

createDataFeedJsonFile(path, initialValue, dataType);

Replace path with the path to the feed's JSON file. Replace initialValue with the feed's initial value. Replace dataType with either "int", "uint", and "str".

To run your data feed, use the following function, and pass it the path to the JSON file you created earlier.

runFeed(path);

This function runs perpetually. At every block, it updates the mostRecent variable in your data Feed smart contract to match the latest value specified in the JSON file you created. You can update the latest value in the JSON file (i.e., the value that runFeed() sends to the blockchain) with the following function.

updateDataFeedJsonFile(path, value);

The value parameter must be of the type that you specified when you created the JSON file.

At every block, runFeed() sets your Feed contract's mostRecent variable to the value at latestValue in the JSON object.