npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

libp2p-middleware-evm

v1.0.6

Published

EVM middleware for libp2p

Downloads

5

Readme

js-libp2p-middleware-evm

Requires https://github.com/libp2p/js-libp2p/pull/3204. Uses https://github.com/dozyio/evm-rule-engine

Example

An slightly contrived example of 2 js-libp2p peers using a EVM blockchain to validate that each peer is holding 1 Eth.

The middleware is run after connection setup and encryption / multiplexing is negotiated but before another stream is setup. The middleware is mutual i.e. both sides run middleware checks, so it should run twice per connection.

If the middleware fails, i.e. a peer isn't holding 1 Eth, the connection closes.

Example Source

// evm.ts
import { tcp } from "@libp2p/tcp"
import { createLibp2p } from "libp2p"
import { noise } from "@chainsafe/libp2p-noise"
import { identify } from '@libp2p/identify'
import { ping } from '@libp2p/ping'
import { yamux } from "@chainsafe/libp2p-yamux"
import { ethers, Wallet } from 'ethers'
import { prefixLogger } from '@libp2p/logger'
import { MiddlewareRegistrar } from 'libp2p-middleware-registrar'
import { middlewareEVM } from 'libp2p-middleware-evm'
import { EVMRuleEngine, createRulesFromDefinitions } from 'evm-rule-engine'
import type { Networks } from 'evm-rule-engine'

const networks: Networks = [
  {
    provider: new ethers.JsonRpcProvider('http://127.0.0.1:8545'),
    chainId: '31337'
  }
]

const engine = new EVMRuleEngine({ networks })

const ruleDefinitions = [
  {
    type: 'walletBalance',
    chainId: '31337',
    params: {
      value: ethers.parseEther('1'),
      compareType: 'gte'
    }
  },
]

const rules = createRulesFromDefinitions(networks, ruleDefinitions)
engine.addRules(rules)

async function newNode(port: string, nickname: string) {
  let signer: Wallet
  if (nickname === 'n1') {
    signer = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80')
  } else if (nickname === 'n2') {
    signer = new Wallet('0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d')
  }
  const node = await createLibp2p({
    logger: prefixLogger(nickname),
    addresses: {
      listen: [
        `/ip6/::/tcp/${port}`
      ]
    },
    transports: [
      tcp(),
    ],
    connectionEncrypters: [noise()],
    streamMuxers: [yamux()],
    services: {
      identify: identify(),
      ping: ping()
    },
    registrar: (components) => {
      const middleware = middlewareEVM({ signer, evmRuleEngine: engine })

      return new MiddlewareRegistrar(components.registrar, middleware(components), components.logger)
    }
  })

  await node.start()

  console.log(`Node started with id ${node.peerId.toString()}`)
  console.log('Mutliaddrs', node.getMultiaddrs())

  return node
}

const n1 = await newNode('12345', 'n1')
const n2 = await newNode('12346', 'n2')

const rtt1 = await n1.services.ping.ping(n2.getMultiaddrs()[0])
console.log('rtt1', rtt1)

Running Example

Run anvil in a terminal window

anvil --port 8545 --chain-id 31337

Run the example with logging (note: use node 23 to run typescript)

DEBUG=* node evm.ts