Socket
Socket
Sign inDemoInstall

@ceramicnetwork/anchor-listener

Package Overview
Dependencies
140
Maintainers
10
Versions
174
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ceramicnetwork/anchor-listener

Ceramic anchor events listener


Version published
Weekly downloads
2.3K
increased by24.91%
Maintainers
10
Created
Weekly downloads
 

Readme

Source

Ceramic Anchor listener

ceramicnetwork MIT license Twitter

Getting started

Installation

$ npm install @ceramicnetwork/anchor-listener

Usage

import {
  createBlockProofsListener,
  createBlocksProofsLoader,
  createAncestorBlocksProofsLoader,
} from '@ceramicnetwork/anchor-listener'
import { take, timeout } from 'rxjs'

// Listen to new block events on the provider and load anchor proofs
const subsription = createBlockProofsListener({ chainId: 'eip155:1', confirmations: 20, provider: ... }).subscribe({
  next(event) {
    // event contains the `block` and `proofs`
  }
})
// Unsubscribe to stop listening
subscription.unsubscribe()

// Load proofs for a range of blocks
createBlocksProofsLoader({ chainId: 'eip155:1', fromBlock: 100, toBlock: 120, provider: ...  }).subscribe({
  next(event) {
    // event contains the `block` and `proofs`
  }
})

// Load proofs for blocks, walking up the parents until the expected ancestor hash is found
createAncestorBlocksProofsLoader({ chainId: 'eip155:1', initialBlock: 'latest', targetAncestorHash: '...', provider: ...  }).pipe(
  // Operators can be used to add stopping conditions
  take(50), // attempt to load maximum 50 blocks
  timeout(300_000), // timeout after 5 minutes
).subscribe({
  next(event) {
    // event contains the `block` and `proofs`
    // unless interrupted, `block.parentHash` will be `targetAncestorHash` in the last event
  }
})

Development

Run tests:

npm test

Run linter:

npm run lint

Contributing

We are happy to accept small and large contributions. Make sure to check out the Ceramic specifications for details of how the protocol works.

License

MIT or Apache-2.0

Keywords

FAQs

Last updated on 22 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc