Noracle
  • Noracle
  • Guides
    • Noracle's Smart Contracts
    • Adding Noracle to your server
Powered by GitBook
On this page
  • On-Chain Access of mostRecent Value
  • Off-Chain Access of the mostRecent Value
  1. Guides

Noracle's Smart Contracts

There are two Noracle smart contracts:

  • VerifySSLCertificate

  • Feed

VerifySSLCertificate allows users to link their domain name to their crypto address and create a data feed. It also stores the following accessor functions: domainToFeed and domainstringToFeed. Both of these take a domain and return the address of the Feed contract linked to the domain.

The Feed contract stores the latest value of the data feed and exposes functions that allow the domain owner (who created the Feed) to update the latest value. There are three variables in which the latest value can be stored:

uint256 public mostRecentUInt;
int256 public mostRecentInt;
string public mostRecentStr;

The Feed owner should use the same data type(s) for the lifetime of their feed. Changing the primary data type(s) of a feed could cause breaking changes in dependent apps.

The mostRecent values can be accessed on-chain or off-chain.

On-Chain Access of mostRecent Value

This is solidity code showing how to access the mostRecent value. It will always be of type int256, uint256, or string. If the feed is reliable, It should never change types.

Feed feedContract = Feed(feedAddress);
int256 mostRecentInt = feedContract.mostRecentInt();
uint256 mostRecentUInt = feedContract.mostRecentUInt();
string memory mostRecentStr = feedContract.mostRecentStr();

Off-Chain Access of the mostRecent Value

const { hethers } = require("@hashgraph/hethers");
const signerId = AccountId.fromString(process.env.SIGNER_ID);
const signerKey = PrivateKey.fromString(process.env.SIGNER_PVKEY);

// Instantiate Provider and Wallet
const provider = hethers.providers.getDefaultProvider("testnet");
const eoaAccount = {
        account: signerId,
        privateKey: `0x${signerKey.toStringRaw()}`, // Convert private key to short format using .toStringRaw()
    };
const wallet = new hethers.Wallet(eoaAccount, provider);


const feedInterface = [
  "function mostRecentInt() view returns (int256)",
  "function mostRecentStr() view returns (string)",
  "function mostRecentUInt() view returns (uint256)",
];

const feedContract = new ethers.Contract(feedAddress, feedInterface, provider);
const feedWithSigner = feedContract.connect(wallet)

let mostRecentInt = await feedWithSigner.mostRecentInt({ gasLimit: 300000 });
let mostRecentUInt = await feedWithSigner.mostRecentUInt({ gasLimit: 300000 });
let mostRecentStr = await feedWithSigner.mostRecentStr({ gasLimit: 300000 });

only one ofmostRecentInt, mostRecentUInt, or mostRecentStrwill be used for any contract. Feeds should not change their data type, or they risk consumers of their feed mishandling their data. In future Noracle versions, this type restriction will be enforced, but now it is just strongly encouraged.

PreviousNoracleNextAdding Noracle to your server

Last updated 3 years ago

off-chain queries can be done by libraries such as , as shown below.

hethers.js