LogoLogo
  • Overview
    • 📎What is Interesting?
    • 📐What we do
      • 🏴‍☠️Private Application Networks
      • 🥠Graph Blockchains
      • ✨Extranet
      • 🔮SD-zkUAN
    • 💡Knowledge Graphs are Interesting
    • 🍨Zero Knowledge Graphs
  • 🔐Cryptography
  • 🚡Hybrid Layer 2
  • 🪙Our Platform Token
  • Guides
    • 📪Creating an Account
    • 📎Creating Blockchain Graphs
    • 👽UAP Tracking App
    • 🧠AI Forever Brain
    • 🛫Decentralized Elon Flight Tracker
  • Intermediate Level
    • 🔗JSON Linked Data
    • 🔏Immutable Graphchains
    • 🕸️The Semantic Web3
    • 📔Smart Functions
    • 🎓Advanced Smart Functions
    • ⛓️Graphchain vs. Blockchain
  • Use Cases
    • 🎨For Artists
    • 🖥️For Developers
    • 🕴️For Business
    • 👷‍♂️For Industry
    • 👨‍🌾For Farmers
    • 🪖For Non Profits
Powered by GitBook

Copyright 2023 - the interesting network

On this page
  1. Guides

Creating Blockchain Graphs

Step 1: Understand Schema Basics in Blockchain-Based Ledger Systems

  • Collections: These act like tables in traditional databases. Define collections to represent different types of entities in your network, such as User, Transaction, Asset, etc.

  • Fields: Fields are attributes or properties within each collection. Specify the data type for each field, such as string, int, boolean, ref (reference to another collection), etc.

  • Predicates: These define the characteristics of the fields, like data type, uniqueness, and whether they are mandatory.

Step 2: Design Your Schema

  • Identify the entities relevant to your network, like User, Transaction, and Asset.

  • Define attributes for each entity. For example, a User might have fields like username, email, and dateJoined.

  • Determine relationships between entities, such as a Transaction referencing a User.

Step 3: Define the Schema

Create a JSON structure to represent your schema:

{
  "collections": [
    {
      "name": "user",
      "fields": [
        { "name": "username", "type": "string", "unique": true },
        { "name": "email", "type": "string" },
        { "name": "dateJoined", "type": "dateTime" }
      ]
    },
    {
      "name": "transaction",
      "fields": [
        { "name": "amount", "type": "float" },
        { "name": "timestamp", "type": "dateTime" },
        { "name": "user", "type": "ref", "collection": "user" }
      ]
    }
  ]
}

Step 4: Implementing the Schema with JavaScript and FlureeQL

To deploy your schema to the Interesting Network, use JavaScript to interact with the blockchain-based ledger via FlureeQL:

  1. Setup Your JavaScript Environment:

    • Ensure Node.js is installed on your system.

    • Initialize a Node.js project in a new directory by running npm init.

    • Install node-fetch for making HTTP requests: npm install node-fetch.

  2. Write Your Deployment Script:

    • Create a file named deploySchema.js in your project directory.

    • Write the script to define your schema and send it to the Interesting Network's local query server:

      const fetch = require('node-fetch');
      
      const schema = {
      // You can have up to 500 something collections within a single ledger
      // if you add more, you may end up having a really shitty response time.
      // Should this happen to you, find a way to contact us and we will discuss
      // ways to help you learn proper schema design.
        "collections": [
          {
            "name": "user",
            "fields": [
              { "name": "username", "type": "string", "unique": true },
              { "name": "email", "type": "string" },
              { "name": "dateJoined", "type": "dateTime" }
            ]
          },
          {
            "name": "transaction",
            "fields": [
              { "name": "amount", "type": "float" },
              { "name": "timestamp", "type": "dateTime" },
              { "name": "user", "type": "ref", "collection": "user" }
            ]
          }
        ]
      };
      
      // Function to deploy the schema, if you read localhost and wonder why 
      // you'll find out soon
      async function deploySchema() {
        try {
          const response = await fetch('http://localhost:8080/fdb/testnetwork/testledger', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ "update": schema.collections })
          });
      // If you are wondering why we are calling localhost:8080, it's because we
      // do some fancy shit by allowing you to operate a query server (or as
      // the neckbeards call it "light client") in browser or via Lattica so you can pub/sub
      // chain data without needing to do much. Check our chain docs for more information.
          if (!response.ok) {
            throw new Error(`HTTP error! Status: ${response.status}`);
          }
      
          console.log('Schema deployed successfully!');
        } catch (error) {
          console.error('Failed to deploy schema:', error);
        }
      }
      
      // Execute the deployment, Mr. Sulu.
      deploySchema();
  3. Run Your Deployment Script:

    • Execute the script with Node.js: node deploySchema.js.

    • The script sends your schema to the Interesting Network's server, creating the necessary collections and fields.

Step 5: Validate and Iterate on the Schema

  • Test the Schema: Insert and query data using FlureeQL to ensure your schema functions as expected.

  • Iterate as Needed: Be open to modifying your schema for new requirements or optimizations.

Additional Considerations for Your Network:

  • Data Access Patterns: Design your schema to cater to expected data access patterns.

  • Unique Features: Utilize features like smart functions or graph queries for advanced data integrity and business logic.

  • Backups and Versioning: Regularly backup and version-control your schema to protect against data loss or accidental changes.

By following these steps, you'll effectively implement and manage your schema in the Interesting Network, utilizing JavaScript and FlureeQL to interact with your blockchain-based ledger system.

PreviousCreating an AccountNextUAP Tracking App

Last updated 1 year ago

If this at all confuses you, this life may not be the one for you and you can click for a cool video that will lead you down a several hour hole to avoid having to learn any of it.

📎
here