Pinata integration

github code

Inspiration

As Artificial Intelligence matures we see a shift in the ecosystem. Initially very limited players like OpenAI dominated the AI space due to state of art model capability and resource. But as the ecosystem grew we saw open-source models becoming more capable and competing against frontier closed source models. We believe this is just the start and in a few years down the line models will become more capable and hardware(with the development of NPUs) will become capable of running these models on consumer end PC. For Example llama3.1 8B which runs on many gaming PC and outperforms GPT3.5 by a huge margin which was state of art exactly 2 years ago in 2022 November.

Our mission aligns closely with a quote from Satya Nadella, CEO of Microsoft.

Satya Nadella -

As AI becomes more capable and agentic, models themselves become more of a commodity, and all value gets created by how you steer, ground, and fine-tune these models with your business data and workflow — and how they compose with the UI layer of human to AI to human interaction

We want to develop a platform where users can develop, train and own their IP and data. We are building a platform where no matter the technical expertise of the user, they can create AI workflow, models, agents and monetize it if they wish to.

The inspiration for NeuraNFT stemmed from a personal desire to customize AI models to better suit individual needs. As I delved deeper into the AI landscape, I uncovered a significant market gap that revolved around the value distribution among key stakeholders in the AI ecosystem. This ecosystem comprises four primary stakeholders:

  1. Data Owners: Individuals or organizations that possess valuable data sets crucial for training AI models.
  2. Model Owners: AI researchers and developers who create and refine AI algorithms and architectures.
  3. Hosting Platforms: Infrastructure providers that offer the computational resources necessary for training and deploying AI models.
  4. End Users: Consumers or businesses that utilize AI models for various applications.

While each of these stakeholders contributes essential value to the AI ecosystem, I observed that the current market structure often fails to equitably distribute the benefits and rewards. For instance:

  • Data owners often have little control over how their data is used and rarely receive direct compensation for its value.
  • Model owners may struggle to monetize their innovations effectively, especially if they lack the resources for large-scale deployment.
  • Hosting platforms, while essential, can sometimes extract disproportionate value due to their control over infrastructure.
  • End users might face high costs or limited customization options, reducing the accessibility and applicability of AI technologies.

This realization led to the conception of NeuraNFT, a platform designed to rebalance the value proposition for all stakeholders involved. By leveraging blockchain technology and NFTs, NeuraNFT aims to:

  • Provide data owners with greater control and potential for monetization of their data.
  • Offer model owners a direct path to market their innovations and receive fair compensation.
  • Create a more competitive and decentralized hosting environment, potentially reducing costs and increasing efficiency.
  • Empower end users with more affordable, customizable, and transparent AI solutions.

Through this approach, NeuraNFT seeks to democratize AI technology, fostering a more equitable, innovative, and collaborative ecosystem that benefits all participants in the AI value chain.

What it does

NeuraNFT is a blockchain-based platform built on the NEAR Protocol that revolutionizes how AI models and datasets are managed, shared, and monetized. By leveraging NEAR's infrastructure and Pinata's decentralized storage solution, we transform AI assets into unique digital tokens (NFTs) while ensuring their immutability and verifiability. This allows creators to maintain ownership while providing a secure way to share and trade their intellectual property.

The platform implements detailed permission controls through smart contracts that let owners specify exactly how their AI models and data can be used. Our decentralized marketplace enables developers, data scientists, and organizations to confidently trade these tokenized assets while protecting intellectual property rights.

NeuraNFT represents a perfect synergy between AI and Web3 technologies, creating an ecosystem where AI development becomes more transparent, accessible, and secure. Our platform ensures secure model deployment and inference, enabling users to utilize AI models without exposing the underlying code or data, thus maintaining the crucial balance between accessibility and security.

Overview

How we built it

NeuraNFT project can be divided into 4 components.

  1. Frontend: build on react
  2. Backends: Flask (Python) and Express(Node)
  3. Storage: Pinata for Decentralized Storage
  4. Smart Contract: Type Script, Java Script and Rust(Rust version is Under Development)
  5. HPC Node: High Performance Computing Node for AI model inference (soon to be replaced by decentralized nodes with DRM) All these services are containerized and can be deployed using a single docker compose. We have also provided debugger configurations if devs want to run these in debug mode.

React Frontend and Near Wallet Integration

The frontend is built in react and integrates with NEAR Wallet. When we deploy the code in production the frontend code is compiled, and the static build is exported to nginx container from where it is deployed. This makes the frontend request comparatively faster than running a native npm server build.

The NeuraNFT team is currently two members, a data scientist and web3 dev with both members having basic full stack knowledge. Said that, we tried to build and scale the application best to our capabilities and optimize it. Though the current app is not super optimized for production and there are still fixes that the application which we plan to take in future such as Server Side Rendering, Lazy loading, graph ql, making more responsive UI and making it more consistent.

We tried to make the design more fun and web3 crypto oriented similar to a NFT marketplace but in future plan to deploy an extension of NeuraNFT more focused on the AI/ML community. Both the platform will be achieving the same thing using the same technology and backend while catering to different communities. The developer portal is also under development which will enable users to create custom AI work flows

Flask, Express backend and Federated AI Learning System

The backend infrastructure employs a distributed Python framework (Flask) orchestrated through Docker containers. The master node architecture handles model deployment and encryption through a implementation of asymmetric cryptography(ECDH + AES). We developed a custom balancer system for signature verification and permission validation, which runs as a separate microservice. Currently this system is centralized but we are developing a distributed DRM layer that will enable secure model deployment enabling users to participate in the network. This layer will combine with the HPC node network to also manage encryption keys like Shamir secrete.

Basically the idea being, user1 can develop AI model or upload data and provide access to user2 to run an inference without actually revealing the data. Permission are on chain. User 2 can request for an inference endpoint through a smart contract, in this case the data will be decrypted on the HPC layer and sent for deployment on a secure node. The nodes would be secure and decentralized. We are currently working on our own Federated Learning protocol which will enable decentralized privacy enabled development and inference of our AI models. We estimate the beta V0.1 version to be completed by Q1 2025. The node express application connects with a quicknode based near node and is primarily used for blockchain query. Initially we planned to develop this in flask itself but there were issues with python integration using pynear(we will be working on the as well and submitting some PR soon). Most interestingly optimization came from implementing this node backend creating a caching mechanism using nginx that reduced repeated meta data access latency by approximately 62%.

We also create a nginx server that acts a reverse proxy for these request and enables metadata request caching. All of these are deployed using docker with a single exposed nginx endpoint.

Pinata Decentralised Storage

Our platform leverages Pinata's decentralized storage infrastructure to handle the crucial aspect of storing and managing large AI assets. Due to blockchain's inherent storage limitations, we cannot store large files like AI models, datasets, and workflow documents directly on-chain. Instead, we store these assets securely in Pinata and maintain only their hash references and metadata on the NEAR blockchain. When creators upload their AI assets to our platform, each file is stored in Pinata with a unique hash that is then linked to the NFT metadata on the blockchain. This architecture ensures complete immutability of the assets and provides a reliable way to verify ownership - crucial features for an AI asset marketplace. The smart contracts store these Pinata references, allowing authorized users to efficiently retrieve the assets while maintaining security. By combining Pinata's robust storage capabilities with NEAR's blockchain infrastructure, we've created a scalable and secure system for managing valuable AI intellectual property.

Another use case of Pinata Storage in our architecture is that it provides a secure verification layer for data ownership and access control. When users request access to an NFT/AI model, our system implements a two-step verification process. First, we validate the user's access level through smart contract permissions. Once verified, we utilize Pinata's storage to retrieve the encrypted data, which is then decrypted only for authorized users before enabling model inference. This integration of Pinata ensures that data ownership and access rights are not just recorded on the blockchain but are actively enforced through our storage and retrieval mechanism, making it an essential component of our platform's security infrastructure.

Smart Contract

We built a specialized NFT smart contract for AI models that solves the tricky problem of managing AI model ownership and access rights on the blockchain. Instead of just basic ownership like regular NFTs, we created a more nuanced system where different users can have varying levels of access to the same model - from basic usage rights all the way up to full ownership and editing capabilities.

We organized everything into collections to keep it clean and manageable. Each collection can represent a family of related AI models, and within each collection, we can mint individual NFTs. What's cool is that we built in a really flexible access control system - so model creators can grant specific permissions to different users. For example, you might let some users just use the model, while others can create derivatives, and others might have full editing rights.

Kindly open the image in a new tab to see in detail

Smart Contract Read functions

For the technical implementation, we used NEAR's blockchain and built everything with security in mind. We made sure to add proper checks so only authorized users can do sensitive stuff like transferring NFTs or updating model data. We also added comprehensive view methods so users can easily see what models they have access to, what permissions they have, and all the associated metadata about the models.

Kindly open the image in a new tab to see in detail

Smart Contract Write

Think of it as a decentralized system for managing AI model rights - kind of like GitHub but for AI models, where everything is backed by blockchain-based ownership and access control.

We developed NeuraNFT on NEAR Protocol, leveraging its wasm based contract code and Nightshade consensus for optimal NFT contract performance. The core implementation uses TypeScript with NEAR SDK-js - chosen specifically for its faster prototype iteration and superior development time compared to Rust but we plan to shift to a rust based contract in near future for more granular control and optimization.

Building on what we created, we've actually designed this as a novel NFT standard called NRC-101 (Neural Request for Comment 101). This specialized standard goes beyond traditional NFT capabilities to specifically address the unique needs of AI model ownership and licensing. Unlike the existing NEP-171 (NEAR's core NFT standard) or NEP-177 (NFT metadata standard) which focus ownership and transfer mechanics, NRC-101 introduces sophisticated concepts like granular access levels, model versioning, and AI-specific metadata structures.

Currently, our NRC-101 implementation isn't directly compatible with widely adopted standards like NEP-171/177 or Ethereum's ERC-721. However, we're developing the Neura Bridge solution to address this. This bridge will allow developers to wrap their NRC-101 tokens into standard-compliant NFTs, enabling them to publish their AI models on popular NFT marketplaces across different blockchains. This means creators won't have to choose between our specialized AI model features and wider market access - they can have both. Through Neura Bridge, they'll be able to tap into established NFT ecosystems while retaining all the sophisticated access control and licensing features that make NRC-101 unique for AI model management.

As we continue building NeuraNFT, our vision extends beyond creating just another NFT marketplace - we're building a comprehensive ecosystem for AI model management and secure deployment. With our NRC-101 standard, upcoming developer portal, and federated learning protocol in development, we're working to revolutionize how AI models are owned, shared, and deployed.

Challenges we ran into

During the development of NeuraNFT, our team encountered several technical challenges that required problem-solving and community support. Initially, we planned to build using Rust, but its steep learning curve prompted us to switch to JavaScript, which offered a more easier development path for us. However, this led to an unexpected hurdle when we discovered that the near-abi package exclusively supported TypeScript contracts. So we has to convert our JavaScript smart contracts to TypeScript to successfully generate the ABI and integrate it with our smart contracts.

During development of our NFT marketplace, I faced the challenge of syncing Pinata access permissions with NFT ownership changes. I solved this elegantly by utilizing NEAR smart contract event emissions. Whenever an NFT transfer occurs, our smart contract emits an ownership transfer event. I built an event listener service that monitors these events in real-time and automatically triggers the necessary Pinata access permission updates. When the listener catches a transfer event, it immediately executes the permission update process - revoking access from the previous owner and granting it to the new owner. This event-driven architecture ensures perfect synchronization between blockchain state and Pinata storage, making the entire process seamless and secure. The solution proved highly reliable as NEAR's event system provides guaranteed delivery and clear transaction timestamps.

Another significant obstacle arose during the testing phase, where setting up test accounts proved more complex than anticipated. Thanks to the supportive NEAR community, we found a solution using the bitte wallet, which streamlined the process of creating and managing test accounts.

The testing phase of our smart contracts initially was a bit time consuming, but the near-cli tool emerged as a game-changer, significantly simplifying our testing and deployment workflow.

Accomplishments that we're proud of

Throughout the development of NeuraNFT, we have achieved several significant milestones.. One of our most notable accomplishments was mastering the nuances of NEAR Protocol and successfully developing smart contracts in three different programming languages - Rust, JavaScript, and TypeScript.

A particularly significant achievement was our successful optimization of the smart contracts for gas efficiency. Through careful architecture and refinements, we were able to minimize transaction costs while maintaining robust functionality, making our platform more accessible and cost-effective for users.

We are also proud of learning about to integrate a private decentralized storage service like pinata in a short time frame which will be very useful when we will add complete dataflows on our application Perhaps our most meaningful accomplishment is creating a system that has the potential to democratize AI ownership and usage while maintaining high security standards. By building NeuraNFT on NEAR Protocol and utilising Pinata, we've developed a platform that makes AI model ownership and trading accessible to a broader audience, while ensuring that creators maintain control over their intellectual property. This balance between accessibility and security represents a significant step forward in the AI and blockchain space.

What we learned

Our journey with NeuraNFT taught us a lot about NEAR Protocol's capabilities. We were impressed by how efficiently it handles transactions - the fees are remarkably low for both transactions and deployments. We had developed contracts in other chains too but the ease of building and deploying contracts in near ecosystem is unbelievable.

A major advantage was NEAR's compatibility with JavaScript. Being able to code in a language that's widely used in the developer community made the development process much more quicker and we were able to handle error more efficiently. It meant we could focus on building features rather than learning the nuances of a new programming language from scratch.

The smart contract naming convention on NEAR proved to be very practical. Unlike other blockchains where you deal with addresses that change with each deployment, NEAR's human-readable contract names made our development process smoother. The persistent data storage meant our work was preserved between deployments, allowing us to iterate effectively.

When it came to deployment, we expanded our technical knowledge by implementing optimization techniques. Using NGINX as our proxy manager significantly improved data retrieval speeds. These backend optimizations made a notable difference in the overall user experience. Integrating Pinata's decentralized storage solution was another key learning experience - we mastered handling large AI documents off-chain while maintaining verifiable ownership through smart contracts. Through Pinata's event-driven architecture, we learned to efficiently manage access controls that automatically sync with NFT ownership changes. These backend optimizations made a notable difference in the overall user experience. Each challenge we faced added to our learning, and every solution improved our understanding of blockchain development. Working with NEAR Protocol and complementary technologies like Pinata has definitely enhanced our skills as developers.

Each challenge we faced added to our learning, and every solution improved our understanding of blockchain development. Working with NEAR Protocol has definitely enhanced our skills as developers.

What's next for NeuraNFT

  1. Smart Contract Optimization: Refine contracts for better performance.
  2. Advanced NFT Functionalities: Implement model combination and fractional/shared ownership features.
  3. Robust Marketplace Development: Create a comprehensive marketplace with advanced search and discovery features.
  4. AI Agents: Developing a platform to enable users to leverage neuranft and develop custom AI agents and AI workflows. Something like ComfyUI but decentralized.
  5. Neura Bridge: Enabling users to wrap NFTs in popular token standards and monetize them on multiple chain and market places
  6. Governance Mechanisms: Introduce decentralized governance for community-driven decision-making.
  7. Expanded Compute Network: Develop a more efficient decentralized compute network for model deployment.
  8. AI-to-AI Interaction Protocols: Enable secure interactions between AI models within the ecosystem.
  9. Cross-chain Interoperability: Explore integration with other blockchain networks.
  10. Industry Partnerships: Establish partnerships with AI researchers, companies, and institutions.

Contract Links

Share this project:

Updates