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 🙏

© 2025 – Pkg Stats / Ryan Hefner

index-provider-peer-id

v1.0.1

Published

Functionality for fetching index provider peer IDs for a minder id on the Filecoin network.

Downloads

92

Readme

index-provider-peer-id

Functionality for fetching index provider peer IDs for a minder id on the Filecoin network.

Usage

Getting a Miner's PeerId

The library provides a function to retrieve a miner's PeerId by querying both the Filecoin smart contract and Filecoin MinerInfo state. It returns the PeerID found in the smart contract, falling back to the PeerID found in MinerInfo state.

The function prioritizes the smart contract result. If the smart contract doesn't return a valid PeerId, it falls back to the result from FilecoinMinerInfo. If both methods fail, an error is thrown with details about the failure.

import {
  getIndexProviderPeerId,
  MINER_TO_PEERID_CONTRACT_ADDRESS,
  MINER_TO_PEERID_CONTRACT_ABI,
} from '@filecoin-station/index-provider-peer-id'
import { ethers } from 'ethers'

// Initialize your ethers contract instance
const provider = new ethers.providers.JsonRpcProvider('https://eth.example.com')
const contract = new ethers.Contract(
  MINER_TO_PEERID_CONTRACT_ADDRESS,
  MINER_TO_PEERID_CONTRACT_ABI,
  provider,
)

// Basic usage
const minerId = 'f0142637'
const { peerId, source } = await getIndexProviderPeerId(minerId, contract)
console.log(peerId) // e.g., '12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG'
console.log(source) // 'smartContract' or 'minerInfo'

// Advanced usage with options
const { peerId, source } = await getIndexProviderPeerId(minerId, contract, {
  maxAttempts: 3, // Number of retry attempts (default: 5)
  rpcUrl: 'https://custom-filecoin-api.com', // Custom Filecoin RPC endpoint (default: 'https://api.node.glif.io/')
  rpcAuth: 'your-auth-token', // Optional authorization token for RPC
  signal: AbortSignal.timeout(60_000), // Optional AbortSignal for cancellation
})

Parameters

  • minerId: A Filecoin miner actor ID (e.g., f0142637)
  • smartContract: An ethers.js Contract instance for the Filecoin smart contract
  • options: (Optional) Configuration object:
    • maxAttempts: Number of retry attempts for RPC calls (default: 5)
    • rpcUrl: Filecoin RPC endpoint URL (default: 'https://api.node.glif.io/')
    • rpcAuth: Authorization token for RPC endpoint (if required)
    • signal: An AbortSignal object for cancelling the rpc request (Only effects the rpc call to the Filecoin API, not the smart contract call)

Return Value

Returns a Promise that resolves to the miner's PeerId string (e.g., 12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG).

Constants

Smart Contract Integration

This library interacts with the MinerPeerIDMapping smart contract on the Filecoin EVM to retrieve peer ID data.

MINER_TO_PEERID_CONTRACT_ADDRESS

The Ethereum address of the deployed MinerPeerIDMapping contract.

MINER_TO_PEERID_CONTRACT_ABI

The ABI required to fetch peer ID and signature data for a given miner ID.

For more information:

Publish

Publish a new version of index-provider-peer-id to npm with the following command:

$ npm run release