Adding Noracle to your server
noracle-js allows you to run a noracle server in Node, or even add Noracle functionality to your existing server. To use, noracle-js, you will need a Hedera account and a certbot SSL certifcate.
Last updated
noracle-js allows you to run a noracle server in Node, or even add Noracle functionality to your existing server. To use, noracle-js, you will need a Hedera account and a certbot SSL certifcate.
Last updated
The library exposes one variable and two functions:
data
linkDomainToAddressAndCreateFeed(pathToCert, pathToPrivateKey)
runFeed()
You can link your domain name to your crypto address with linkDomainToAddressAndCreateFeed
. It takes two functions: pathToCert, the path to the .pem file containing your SSL certificate, and pathToPrivateKey, the path to the .pem file containing the private key associated with your SSL certificate. Under the hood, this function calls the VerifySSLCertificate smart contract.
The runFeed()
function runs perpetually. At every block, it submits to your Feed contract the value contained the data.latestValue
.
Regularly update data.latestValue
to the most recent value in your data feed. Set data.type
to the type you are using, either "uint", "int", or "str".
This section contains a full walkthrough for setting up noracle on your server so that you can run your own data feed. We assume you have access to the following.
The PEM file containing the SSL certificate for your domain.
The PEM file containing the private key associated with your SSL certificate
You can generate PEM SSL certificates with and .
Create a new folder for your noracle scripts.
mkdir my-noracle
cd my-noracle
npm init
Install noracle-js with the following command.
npm install noracle-js
You will need to run multiple scripts. Create the following JavaScript files.
touch setup.js
touch runDataFeed.js
touch runFeedUpdater.js
Import noracle-js into each of these scripts.
const noracle = require('noracle-js');
In order to submit transactions to the blockchain (when verifying your SSL certificate and updating your data feed), noracle-js requires access to your Hedera account. It uses the account specified by the following two environment variables.
If these variables are not set, if each one points to a different account, or if they are otherwise incorrect, then noracle-js will not work.
We recommend setting these variables in a .env file in the root of your project folder. The .env file will look sommething like the following.
Locate on your server the .pem file that stores your domain's SSL certificate and the .pem file that stores the certificate's private key. You need the paths to these files.
In your setup.js script, add the following line.
noracle.linkDomainToAddressAndCreateFeed(pathToCert, pathToPrivateKey);
Replace pathToCert
and pathToPrivateKey
with the correct paths.
Add the following line to create the local JSON file that noracle-js will use as the source of truth for your data feed.
noracle.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".
Run the script. This will, first, create a veriable link between your Hedera account and your website's domain name and, second, create the local JSON file for your data feed.
Open runDataFeed.js and add the following line.
noracle.runFeed(path)
Replace path
with the path to the JSON file you created.
Run this script when you want to start sending data to the blockchain. The runFeed()
function runs perpetually until you kill it or an unexpected error occurs. If your account runs out of funds to submit transactions, runFeed()
will quit with an error.
Open runFeedUpdater.js and add the following line.
noracle.updateDataFeedJsonFile(path, value)
Replace path
with the path to the JSON file you created, and replace value
with your feed's latest value.
You can now populate this script with the data retrieval implementation that best suites your situation.
That is everything! You have created a verifiable (and verified) link between your Hedera account and your domain name, a link which attests to the fact that you own both and that data about your domain from your account is trustworthy. You have set up your server to run your website-to-blockchain data feed.
Follow the instructions to create an account for the Hedera blockchain.
You need to fund your account in order to submit transactions to the blockchain. You can obtain HBAR, Hedera's native currency, through a cryptocurrency exchange such as . Once you buy some HBAR through an exchange, you need to transfer it to the account you created. The exchange should have a feature that allows you to do this.