erebos

erebos

  • Docs
  • Examples
  • API
  • Help
  • GitHub

›Swarm examples

Docs

  • Introduction
  • Getting started

Swarm examples

  • File storage examples
  • Feeds examples
  • Communications examples

Swarm APIs and CLI

  • Swarm client
  • Individual APIs
  • Bzz API
  • Bzz Feed API
  • Bzz FS API
  • Pss API
  • CLI

Data structures

  • Data structures
  • Feed lists
  • Document synchronization
  • Timeline

Timeline protocol

  • Timeline specification
  • Timeline example
  • Timeline API

Utility libraries

  • Hexadecimal encoding
  • Keccak256 hashing
  • SECP256k1 signing
  • Hierarchical Deterministic wallet

RPC tools

  • RPC clients, handler and transport
  • Base RPC class and types
  • RPC Errors
  • RequestRPC client (stateless)
  • StreamRPC client (stateful)
  • RPC handler
  • RPC client over HTTP
  • RPC client over WebSocket
  • RPC client over IPC
  • RPC client for browsers
  • RPC client for Node
  • RPC client for Electron
  • HTTP transport
  • WebSocket transport
  • IPC transport
  • Electron transport
Edit

Communications examples

Communication APIs reference

Communication between two nodes using asymmetric encryption

import { SwarmClient } from '@erebos/swarm-node'

const run = async () => {
  // Create PSS clients over WebSocket
  const alice = new SwarmClient({ pss: 'ws://localhost:8501' })
  const bob = new SwarmClient({ pss: 'ws://localhost:8502' })

  // Retrieve Alice's public key and create the topic
  const [key, topic] = await Promise.all([
    alice.pss.getPublicKey(),
    alice.pss.stringToTopic('PSS rocks'),
  ])

  // Make Alice subscribe to the created topic and Bob add her public key
  const [subscription] = await Promise.all([
    alice.pss.subscribeTopic(topic),
    bob.pss.setPeerPublicKey(key, topic),
  ])

  // Actually subscribe to the messages stream
  alice.pss.createSubscription(subscription).subscribe(payload => {
    console.log(
      `received message from ${payload.key}: ${payload.msg.toString()}`,
    )
  })

  // Send message to Alice
  bob.pss.sendAsym(key, topic, 'hello world')
}

run().catch(console.error)

Communication between two nodes without encryption

import { SwarmClient } from '@erebos/swarm-node'

const run = async () => {
  // Create PSS clients over WebSocket
  const alice = new SwarmClient({ pss: 'ws://localhost:8501' })
  const bob = new SwarmClient({ pss: 'ws://localhost:8502' })

  // Retrieve Alice's node address and create the topic
  const [address, topic] = await Promise.all([
    alice.pss.baseAddr(),
    alice.pss.stringToTopic('PSS rocks'),
  ])

  // Make Alice subscribe to the created topic
  const subscription = await alice.pss.subscribeTopic(topic, true)

  // Actually subscribe to the messages stream
  alice.pss.createSubscription(subscription).subscribe(payload => {
    console.log(`received message: ${payload.msg.toString()}`)
  })

  // Send message to Alice
  bob.pss.sendRaw(address, topic, 'hello world')
}

run().catch(console.error)
← Feeds examplesSwarm client →
  • Communication between two nodes using asymmetric encryption
  • Communication between two nodes without encryption
Docs
Getting StartedAPI ReferenceCLI
Community
Gitter chatGitHub repositoryStar
Swarm
Official documentationHTTP gatewayDevelopment chat