### Install Axios HTTP Client with npm Source: https://docs.vana.org/reference/json-rpc-api-quickstart Installs the Axios library, a popular promise-based HTTP client for the browser and Node.js, which will be used for making API requests. ```shell npm install axios ``` -------------------------------- ### Clone and Install Vana Smart Contracts Source: https://docs.vana.org/docs/manual-setup-guide-advanced This snippet clones the Vana smart contracts repository, navigates into the directory, fetches the main branch, checks it out, installs dependencies, and copies the example environment file. ```bash git clone https://github.com/vana-com/vana-smart-contracts.git cd vana-smart-contracts git fetch origin main git checkout main npm install cp .env.example .env ``` -------------------------------- ### Clone and Install UI Template Source: https://docs.vana.org/docs/5-launch-datadao-ui Clones the DataDAO UI template repository, installs its dependencies using yarn, and sets up the environment file from a template. This is the initial setup step for the front-end application. ```shell git clone https://github.com/vana-com/dlp-ui-template cd dlp-ui-template yarn install cp .env.example .env ``` -------------------------------- ### Install Axios HTTP Client with yarn Source: https://docs.vana.org/reference/json-rpc-api-quickstart Installs the Axios library, a popular promise-based HTTP client for the browser and Node.js, which will be used for making API requests. ```shell yarn add axios ``` -------------------------------- ### Create and Initialize Project with npm Source: https://docs.vana.org/reference/json-rpc-api-quickstart Commands to create a new project directory and initialize it using npm's package manager. This sets up the basic structure for a Node.js project. ```shell mkdir ethereum-api-quickstart cd ethereum-api-quickstart npm init --yes ``` -------------------------------- ### Create and Initialize Project with yarn Source: https://docs.vana.org/reference/json-rpc-api-quickstart Commands to create a new project directory and initialize it using yarn's package manager. This sets up the basic structure for a Node.js project. ```shell mkdir vana-api-quickstart cd vana-api-quickstart yarn init --yes ``` -------------------------------- ### Install Vana SDK and Viem Source: https://docs.vana.org/docs/sdk This command installs the Vana SDK and Viem, a popular Ethereum utility library, using npm. These are the primary dependencies for building applications with the Vana SDK. ```bash npm install @opendatalabs/vana-sdk viem ``` -------------------------------- ### Example Environment Variables for Testing Source: https://docs.vana.org/docs/manual-setup-guide-advanced This snippet provides example values for the environment variables used in DataDAO deployment. These are for format reference and should not be used in production environments. They include a sample private key, owner address, and public key. ```env DEPLOYER_PRIVATE_KEY=48fe86dc5053bf2c6004a24c0965bd2142fe921a074ffe93b440f0ada662d16d OWNER_ADDRESS=0x18781A2B6B843E0BBe4F491B28139abb6942d785 DLP_PUBLIC_KEY=04920ff366433d60fcebfa9d072d860e6fd7a482e4c055621ef986025076c9fb6418c15712a22bff61a3add75b645345c7c338f19a8ab0d1a3ac6be1be331eac45 ``` -------------------------------- ### Run JavaScript Script Source: https://docs.vana.org/reference/json-rpc-api-quickstart Command to execute a Node.js script from the terminal. This is used to run the `index.js` file containing the Vana API request. ```shell node index.js ``` -------------------------------- ### Run DataDAO UI Development Server Source: https://docs.vana.org/docs/5-launch-datadao-ui Starts the development server for the DataDAO UI using npm. Access the running UI at http://localhost:3000 in your web browser. ```bash npm run dev ``` -------------------------------- ### Install The Graph CLI Source: https://docs.vana.org/docs/the-graph Installs the Graph Command Line Interface globally on your local machine. This tool is essential for managing and deploying subgraphs. ```shell npm install -g @graphprotocol/graph-cli ``` -------------------------------- ### JSON Example for Schedules Parameter Source: https://docs.vana.org/docs/how-to-create-and-deploy-a-vrc-20-token This JSON array defines multiple vesting schedules for Vana LLM's DataDAO tokens. Each object specifies the beneficiary, start time, cliff duration, total vesting duration, and the amount of tokens with 18 decimals. Ensure the duration is greater than the cliff. ```json [ { "beneficiary": "0x...", "start": 1717977600, "cliff": 15778463, "duration": 31556926, "amount": "500000000000000000000000" }, { "beneficiary": "0x...", "start": 1717977600, "cliff": 15778463, "duration": 63113852, "amount": "250000000000000000000000" } ] ``` -------------------------------- ### Install Gelato Relay SDK using Yarn Source: https://docs.vana.org/docs/gelato-relay This command installs the Gelato Relay SDK, a necessary package for integrating Gelato's gasless transaction functionality into your project. Ensure you have Node.js and Yarn installed. ```bash yarn add @gelatonetwork/relay-sdk ``` -------------------------------- ### Query GraphQL Subgraph using Rust Source: https://docs.vana.org/docs/subgraph-general Provides an example of querying a GraphQL subgraph using the 'graphql-client' and 'reqwest' crates in Rust. This approach uses compile-time generation based on schema and query files or can be adapted for raw HTTP POST requests. It requires the 'graphql-client', 'reqwest', and 'tokio' crates. ```rust use graphql_client::{GraphQLQuery, Response}; use reqwest; #[derive(GraphQLQuery)] #[graphql( schema_path = "schema.graphql", query_path = "query_file.graphql", response_derives = "Debug" )] struct GetUsers; #[tokio::main] async fn main() -> Result<(), Box> { let variables = get_users::Variables {}; let client = reqwest::Client::new(); let res = client .post("https://YOUR_SUBGRAPH_ENDPOINT") .json(&GetUsers::build_query(variables)) .send() .await? .json::>() .await?; if let Some(data) = res.data { println!("{:?}", data); } Ok(()) } ``` -------------------------------- ### Example Local Test Output JSON Source: https://docs.vana.org/docs/3-set-data-verification-logic An example of the expected JSON output in `output/results.json` after running the local Docker test. This structure represents the data that will eventually be written on-chain. ```json { "dlp_id": 1234, "valid": true, "score": 1.0, "authenticity": 0, "ownership": 1.0, "quality": 1.0, "uniqueness": 0, "attributes": { "total_score": 0.5, "score_threshold": 0.04, "email_verified": true }, "metadata": { "dlp_id": 1234 } } ``` -------------------------------- ### Get Latest Block Number Source: https://docs.vana.org/reference/json-rpc-api-quickstart This endpoint retrieves the most recent block number on the Vana blockchain using a POST request to the JSON-RPC API. ```APIDOC ## GET Latest Block Number ### Description This endpoint retrieves the most recent block number on the Vana blockchain. ### Method POST ### Endpoint `https://rpc.{network}.vana.org/` ### Parameters #### Query Parameters None #### Request Body - **jsonrpc** (string) - Required - Specifies the JSON-RPC protocol version, should be '2.0'. - **id** (number) - Required - An identifier for the request. - **method** (string) - Required - The name of the method to be invoked, 'eth_blockNumber' for this endpoint. - **params** (array) - Optional - An empty array for the 'eth_blockNumber' method. ### Request Example ```json { "jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": [] } ``` ### Response #### Success Response (200) - **jsonrpc** (string) - The JSON-RPC protocol version. - **id** (number) - The identifier of the request. - **result** (string) - The latest block number as a hexadecimal string. #### Response Example ```json { "jsonrpc": "2.0", "id": 1, "result": "0xcafebeef" } ``` ``` -------------------------------- ### Vana Refinement Service POST Request Example Source: https://docs.vana.org/docs/data-refinement-publishing An example JSON payload for triggering the Vana Refinement Service via a POST request. This includes essential parameters like file ID, encryption key, refiner ID, and environment variables for services like Pinata. ```json POST /refine Content-Type: application/json { "file_id": 1234, "encryption_key": "0xabcd1234...", "refiner_id": 12, "env_vars": { "PINATA_API_KEY": "xxx", "PINATA_API_SECRET": "yyy" } } ``` -------------------------------- ### Dataset Schema Definition Example Source: https://docs.vana.org/docs/data-refinement-publishing An example JSON object defining a dataset schema. This structure specifies the dataset's name, version, description, dialect (e.g., 'sqlite'), and the SQL CREATE TABLE statement for its schema. This definition must be uploaded to a decentralized storage provider like IPFS. ```json { "name": "social_media_posts", "version": "0.0.1", "description": "Refined social media dataset", "dialect": "sqlite", "schema": "CREATE TABLE posts (id INTEGER PRIMARY KEY, user_id TEXT, content TEXT, timestamp DATETIME);" } ``` -------------------------------- ### Build and Run Refiner Docker Image Source: https://docs.vana.org/docs/4-make-data-queryready This command builds a Docker image tagged 'refiner' and then runs it. The command mounts local directories for input and output, passes environment variables from a .env file, and executes the refiner. This process generates the refined database and schema files. ```bash docker build -t refiner . docker run \ --rm \ -v $(pwd)/input:/input \ -v $(pwd)/output:/output \ --env-file .env \ refiner ``` -------------------------------- ### Build and Run PoC Docker Image Locally Source: https://docs.vana.org/docs/3-set-data-verification-logic Builds a Docker image named `my-proof` from the current directory and then runs it. This command mounts local `input` and `output` directories into the container and sets the `USER_EMAIL` environment variable for local testing. The results are written to `output/results.json`. ```shell docker build -t my-proof . docker run \ --rm \ -v $(pwd)/input:/input \ -v $(pwd)/output:/output \ --env USER_EMAIL=user123@gmail.com \ my-proof ``` -------------------------------- ### Make Vana API Request for Latest Block Number Source: https://docs.vana.org/reference/json-rpc-api-quickstart A JavaScript code snippet using Axios to send a JSON-RPC request to the Vana API to fetch the latest block number. It defines the API endpoint and the request payload, then handles the response or any errors. ```javascript import axios from "axios"; const url = `https://rpc.{network}.vana.org/`; const payload = { jsonrpc: '2.0', id: 1, method: 'eth_blockNumber', params: [] }; axios.post(url, payload) .then(response => { console.log('The latest block number is', parseInt(response.data.result, 16)); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### Example SQL Query for Data Access Source: https://docs.vana.org/docs/the-data-lifecycle This snippet demonstrates a typical SQL query used by AI builders to retrieve specific subsets of structured data from a refined dataset. It illustrates how data can be filtered and selected based on defined criteria. ```sql SELECT user_age, daily_steps FROM fitness_data WHERE activity_level = 'high' ``` -------------------------------- ### Clone Data Refinement Template Repository Source: https://docs.vana.org/docs/4-make-data-queryready This command clones the Data Refinement template repository from GitHub. Ensure you replace YOUR_GITHUB_USERNAME with your actual GitHub username. This repository serves as the base for your data refinement process. ```shell git clone https://github.com/YOUR_GITHUB_USERNAME/vana-data-refinement-template.git cd vana-data-refinement-template ``` -------------------------------- ### Commit and Push Changes Source: https://docs.vana.org/docs/4-make-data-queryready These commands add all changes to the staging area, commit them with a descriptive message, and push the commit to the 'main' branch of the origin remote. This action triggers the GitHub pipeline for building the refiner. ```bash git add . git commit -m "Set up refiner for the DataDAO" git push origin main ``` -------------------------------- ### Create Public Key and Encrypt Secret using OpenSSL Source: https://docs.vana.org/docs/data-validation This snippet demonstrates how to create a public key file and then use it to encrypt a sensitive value like a password. The encryption uses OAEP padding with SHA256. The output is a hex-encoded string suitable for inclusion in a request. ```bash # Create the public key echo "-----BEGIN PUBLIC KEY----- MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA4129oK+dUEalpqP5aT/M A6yhFbAjNppOidQuVgeSgEPquXLlJrdLoomHGhzugbBYeKS6lceEDM3oygFdCGhT sly26Ws8qyUIGlk0/JGf4mRHd9RMs0uOF50/mB4abNM/mA/k8cO46+UmXOK2rwEL U2rPb5tWVzxjPqs8Aw9eT1n7UlvOXxFc4ChyIHX/plfbkKK1R1+PYhtBHeQT8aW1 o7wLsbbnkCGh2iahJaNacMWmUZ9YygdPg2DICQLK2KbZfZHhhylBjDzuBgjUzNai ikVHzrR6f9eTihYjmpx8Br5Ubhj3lVt45nAXFidxMBe1e7IILNVl9C57sqV+nPFM 2s5ad/r3TDjOZ23e0FGBVsyG+lJwn9q/kx4kjSFsO8fNzJ7wUczVnfW+akox2rMX rnvdxUhpAAEtJZme5+pnS6Fr4Zi8mUBPt9kC/mHTtbPQoLsX+FeBs/u+rpXe4xBr +QhqShKWQ+4HzwQHCc5h9d4pqZEKK8UnpdeJ0c/QTqcVAgMBAAE= -----END PUBLIC KEY-----" > public_key.pem # Encrypt a sensitive value, ex: "my_password" echo -n "my_password" | openssl pkeyutl -encrypt -pubin -inkey public_key.pem -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 | xxd -p -c 256 | tr -d '\n' ```