Skip to main content

Querying

Network users can access data through a permissionless model by connecting a crypto wallet to create an account. To obtain necessary credentials, users can stake stablecoin tokens in a billing smart contract, which deducts tokens based on usage. Stablecoins maintain a stable service price, enabling users to plan and budget account top-ups. Upon the initial login, users receive a default billing account, featuring a trial account for testing and integration. Users can manage multiple application integrations or resell services through multiple billing accounts. The network records activity to IPFS-backed storage, periodically aggregating data. The resulting file's hash is recorded in the blockchain, preventing data manipulation. The billing contract looks up the blockchain for aggregated file details, using this information to retrieve data from IPFS and deducting from user deposits based on usage.

How to Guides

Query data from the network

  1. Create a billing account in the network interface https://app.bitscrunch.com/ .

  2. Deposit stablecoin to get access to the data in the network.

  3. Download access key from the network interface and retrieve the details such as name, key, and public key from the credential file.

  4. Use the provided template script to query data from the network.

    • Create a folder called bitscrunch and open it in VSCode or other code editor.

    • Open terminal and initialize node project

      npm init -y
    • Install required node packages.

      npm install uuid crypto
    • Copy the downloaded access key and paste it in bitscrunch folder as access-key.json.

    • Save the template provided below as query.js.

      query.js
      const uuid = require("uuid");
      const uuidV1 = uuid.v1;
      const crypto = require("crypto");
      const accessKey = require('./access-key.json')

      // Details from access_key.json generated from decentralization interface
      const key = accessKey.key;
      const publicKey = accessKey.publicKey;
      const name = accessKey.name;

      // API url for the decentralized network
      // mainnet: https://api.bitscrunch.com
      // testnet: https://api-testnet.bitscrunch.com
      const host = "https://api.bitscrunch.com";

      // Request path
      const path =
      "/api/v1/market/metrics?currency=usd&blockchain=1&metrics=holders&metrics=marketcap&time_range=24h&include_washtrade=true";
      const body = "";

      // create uuid1 based request id
      const buffer = Buffer.alloc(16);
      uuidV1({}, buffer);
      const r_id = buffer.toString("hex");
      const message = r_id + ":GET:" + path + ":" + body + ":";

      // sign the message with the provided key
      const getSignedHeaders = (key, message) => {
      const cKey = crypto?.createPrivateKey({
      key: `-----BEGIN PRIVATE KEY-----\n${key}\n-----END PRIVATE KEY-----`,
      format: "pem",
      cipher: "fips-186-3",
      });
      const data = Buffer.from(`${message}`);
      const sign = crypto.sign("SHA256", data, cKey);
      const signature = sign.toString("base64");
      return signature;
      };
      const signature = getSignedHeaders(key, message);

      // build required headers
      const options = {
      method: "GET",
      headers: {
      accept: "application/json",
      rid: r_id,
      sign: signature,
      name: name,
      pubkey: publicKey,
      message: message,
      },
      };

      // query the network with necessary headers
      fetch(`${host}/${path}`, options)
      .then((response) => response.json())
      .then((response) => console.log(response))
      .catch((err) => console.error(err));
  5. Execute the script in the terminal

    node query.js
note

The secure storage of the private key is the user's responsibility.