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
Create a billing account in the network interface https://app.bitscrunch.com/ .
Deposit stablecoin to get access to the data in the network.
Download access key from the network interface and retrieve the details such as name, key, and public key from the credential file.
Use the provided template script to query data from the network.
- JavaScript
- Python
Create a folder called
bitscrunchand open it in VSCode or other code editor.Open terminal and initialize node project
npm init -yInstall required node packages.
npm install uuid cryptoCopy the downloaded access key and paste it in
bitscrunchfolder asaccess-key.json.Save the template provided below as
query.js.query.jsconst 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));
Create a folder called
bitscrunchand open it in VSCode or other code editor.Install the below package.
pip install pycryptodomeCopy the downloaded access key and paste it in
bitscrunchfolder asaccess-key.json.Save the template provided below as
query.py.query.pyimport requests
from Crypto.Hash import SHA256
from Crypto.PublicKey import ECC
from Crypto.Signature import DSS
import base64
import uuid
import json
file_path = 'access-key.json'
with open(file_path, 'r') as file:
access_key = json.load(file)
# Details from access_key.json generated from decentralization interface
key = access_key["key"]
publicKey = access_key["publicKey"]
name = access_key["name"]
# API url for the decentralized network
# mainnet: https://api.bitscrunch.com
# testnet: https://api-testnet.bitscrunch.com
host = "https://api.bitscrunch.com"
# Request path
path = "/api/v1/market/metrics?currency=usd&blockchain=1&metrics=holders&metrics=marketcap&time_range=24h&include_washtrade=true"
body = ""
# create uuid1 based request id
request_id = uuid.uuid1().hex
# message to be signed
message = request_id + ':GET:' + path + ':' + body + ':'
# sign the message with the provided key
def sign_message(key, message):
c_key = ECC.import_key(
'-----BEGIN EC PRIVATE KEY-----\n' + key + '\n-----END EC PRIVATE KEY-----')
h = SHA256.new(message.encode('utf-8'))
signer = DSS.new(c_key, 'fips-186-3', encoding="der")
signature = signer.sign(h)
return base64.b64encode(signature)
signature = sign_message(key, message)
# build required headers
headers = {
'rid': request_id,
'name': name,
'sign': signature,
'pubkey': publicKey,
'message': message
}
# query the network with necessary headers
response = requests.get(host + path, headers=headers)
print(response.json())
Execute the script in the terminal
- JavaScript
- Python
node query.jspython query.py
The secure storage of the private key is the user's responsibility.