Decentralised Pub/Sub Network
  • What is Pub/Sub
  • DPSN + Virtual Protocol: Empowering 17,000+ AI Agents with Real-Time Data
  • DPSN + GOAT SDK: Real-Time Data Streams Now Live
  • How to Publish Real-Time Data Streams on DPSN: A Guide for Developers
  • How to Subscribe to DPSN Data Streams: A Guide for Developers
  • Real-Time Market Intelligence for AI Agents: The DPSN Approach
  • MCP vs. Bridging Agents: Which One Powers AI Agents Best?
  • How DPSN Unlocks 99% of the Data
  • AI Agent Builders+DPSN: Unlocking Real-Time, Scalable Intelligence
  • DPSN+MCP: Bridging Real-Time Data for AI Agents
  • Improving AI Agent Decision-Making with Workflow Tags and JSON
  • Exploring DPSN SDK: Transforming Pub/Sub Networks in a Decentralised World
  • DPSN: Secure and Scalable Real-Time Messaging for a Decentralized Future
  • Understanding Price Feed Oracles and Why DPSN Is Essential for Decentralized Infrastructure
  • How DPSN supports Fully Homomorphic Encryption to Secure Data
  • Revolutionizing Data Feeds: How DPSN is Democratizing Web3 Connectivity
  • Enhancing Machine-to-Machine Communication in DePIN: How DPSN Powers Data Transfer
  • How DPSN Powers High-Throughput, Low-Latency Applications
  • DPSN for DeFi: Powering High-Speed Oracles and Financial Innovation
  • Harnessing DPSN for IoT: A Game-Changer for Smart Cities and Beyond
  • Building Resilient dApps: How DPSN Drives Scalability and Security
  • DPSN vs. Centralized Systems: A Case for Decentralization
  • Topic Ownership and Privacy in DPSN: Why It Matters for Developers
  • ChainPulse & DPSN: Revolutionizing Decentralized Communication for Web3
  • Boosting High-Performance Applications with DPSN's Advanced Clusters
  • The Evolution of Decentralized Messaging: From Bitcoin to DPSN
  • Optimizing Smart City Infrastructure with DPSN’s IoT Data Handling
  • Building Censorship-Resistant Applications with DPSN
  • 5 Key Features That Make DPSN Stand Out in Blockchain Networks
  • 7 Ways DPSN Enhances Data Privacy and Security
  • 6 Innovations in DPSN That Are Shaping the Blockchain Ecosystem
  • How DPSN is Transforming Data Security in Financial Applications
  • How DPSN Powers Secure Data Sharing in the Era of IoT Expansion
  • Exploring DPSN’s Role in Blockchain Interoperability
  • How DPSN Enhances Decentralized Messaging for Web3 Innovation
  • Why DPSN's Pub-Sub Model is Perfect for Web3
  • DPSN as the Backbone of Real-Time Messaging for Blockchain
  • How to Set Up Topic-Based Messaging in DPSN
  • 5 Common Challenges in Blockchain Communication and How to Solve Them
  • AI Agents Need Real-Time Data, DPSN Delivers
  • DPSN Dynamic Streams: The Future of Real-Time, Decentralized Data Feeds
  • Why Real-Time Data is the Next Frontier for Web3
Powered by GitBook
On this page
  • Understanding DPSN Data Streams
  • Topics: The Foundation of Data Streams
  • How Topic Ownership Works (The Foundation of Streams)
  • Quick Guide: Creating and Publishing Data Streams
  • Best Practices for Data Stream Publishers
  • Need Custom Solutions?

How to Publish Real-Time Data Streams on DPSN: A Guide for Developers

PreviousDPSN + GOAT SDK: Real-Time Data Streams Now LiveNextHow to Subscribe to DPSN Data Streams: A Guide for Developers

Last updated 1 month ago

In today's digital landscape, real-time data delivery is essential for AI systems and applications. DPSN provides developers with a decentralized infrastructure to create and publish secure data streams with blockchain-verified ownership. This guide shows you how to turn topics into valuable real-time data streams on the DPSN network.

Understanding DPSN Data Streams

Data streams in DPSN function as:

  • Ownership-based channels: Each stream is owned by the wallet that purchases the underlying topic

  • Real-time data pipelines: Publishers push continuous data to create streams that subscribers receive in real-time

  • Permissioned resources: Only the topic owner can publish to the stream, while anyone can subscribe to it

  • Authenticated channels: The blockchain provides the authentication and ownership layer

Think of data streams as secure broadcast channels where data integrity and publisher authenticity are guaranteed by blockchain verification.

Topics: The Foundation of Data Streams

Before creating a data stream, you need to understand topics:

  • Topics are the foundational data unit you mint on DPSN infrastructure

  • Topics establish your ownership of a specific data distribution channel

  • Each topic is secured by blockchain-verified ownership

  • You can create sub-topics under a single topic if you wish to publish different types of data

A topic becomes a stream when you consistently push data to it. By minting a topic and then publishing real-time data to it continuously, you transform it into a valuable data stream that others can subscribe to, creating direct monetization potential for your data.

How Topic Ownership Works (The Foundation of Streams)

When you mint a topic to create a stream:

  1. Your wallet initiates a blockchain transaction to the DPSN smart contract on the Base Sepolia network

  2. This transaction:

  • Requires at least 0.002 Base Sepolia ETH

  • Associates the topic name with your wallet's address in the contract

  • Generates a unique topicHash that becomes owned by your wallet

3. Authentication works through:

  • Your wallet's private key signing messages when publishing data to the topic

  • The DPSN nodes verifying that only the registered owner can publish to that topic

By continuously publishing to your owned topic, you create a data stream that subscribers can reliably access.

Quick Guide: Creating and Publishing Data Streams

npm install dpsn-client

# or

yarn add dpsn-client

2. Import and Initialize the Client

import { DpsnClient } from 'dpsn-client';

To initialize and authenticate with DPSN services, you’ll need an EVM wallet private key:

Use an EVM wallet: Create or use an existing Ethereum-based wallet, preferably on testnet for security.

Add your RPC details:

  • DPSN URL: betanet.dpsn.org

  • DPSN Smart Contract Address: 0xC4c4CFCB2EDDC26660850A4f422841645941E352 (on Base Sepolia testnet)

  • BASE RPC URL: URL from any Base testnet RPC provider

Get your private key: Export it from your wallet’s security settings. Configure the client:

const dpsnClient = new DpsnClient(
    "betanet.dpsn.org",  // DPSN network endpoint
    "<YOUR_EVM_WALLET_PRIVATE_KEY>",  // Your EVM wallet private key
    {
        network: 'testnet',
        wallet_chain_type: 'ethereum'
    }
);

3. Configure Blockchain Settings

// Set blockchain configuration
dpsnClient.setBlockchainConfig(
    "YOUR_TESTNET_BASE_RPC_URL",           // Your Base testnet RPC URL
    "0xC4c4CFCB2EDDC26660850A4f422841645941E352"   // DPSN contract address
);

4. Check Topic Minting Price

// Get the current price for minting a topic
const price = await dpsnClient.getTopicPrice();
console.log("Topic minting price:", price.toString());

5. Mint a Topic (The Foundation of Your Stream)

try {
    // Mint a new topic 
    const { receipt, topicHash } = await dpsnClient.purchaseTopic("YOUR_TOPIC_NAME");
    console.log("Successfully minted topic:", topicHash);
    console.log("Transaction receipt:", receipt);
} catch (error) {
    console.error("Failed to mint topic:", error);
}

6. Fetch Your Owned Topics

// Fetch all topics you own
const ownedTopics = await dpsnClient.fetchOwnedTopics();
console.log("Your topics:", ownedTopics);

7. Transform Your Topic into a Stream by Publishing Real-Time Data

try {
    // Publish data to your topic
    // A message can be JSON, string, or binary data e.g.
    const message = {
        timestamp: Date.now(),
        data: "Your message content",
        metadata: {
            source: "your-app",
            version: "1.0"
        }
    };


    await dpsnClient.publish(topicHash, message);
    console.log("Successfully published message to topic:", topicHash);
} catch (error) {
    console.error("Failed to publish message:", error);
}

Best Practices for Data Stream Publishers

To maximize the effectiveness of your real-time data streams:

  • Consistent Publishing: Transform your topic into a valuable stream by publishing data consistently

  • Stream Quality: Ensure your stream provides timely, accurate data that subscribers can rely on

  • Error Handling: Implement proper error handling for both blockchain transactions and data publishing

  • Gas Management: Monitor gas prices and set appropriate gas limits for topic minting transactions

  • Data Validation: Validate data before publishing to ensure it meets your stream's requirements

  • Transaction Monitoring: Track transaction status and implement retry mechanisms for failed transactions

Need Custom Solutions?

1. Install the using npm or yarn:

Minimum balance needed: 0.002 Base Sepolia ETH to mint a topic. You can mint the faucet tokens from .

For custom data stream requirements, lower latency options, or specialized topic configurations, please reach out to us on telegram -. We offer customized solutions for enterprise clients and high-frequency applications, including tailored data publishing infrastructure for time-sensitive systems.

DPSN Client SDK
here
https://t.me/dpsn_dev