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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fairdatasociety/fdp-contracts

v1.0.4

Published

Library for interaction with FDS contracts

Downloads

22

Readme

FDS Contracts JS Library

This library provides simple interface to interact with FDS contracts.

Installation

The library depends on the ethers.js library. So in order to use the library, ethers must be installed.

To install the both libraries:

npm install --save @fairdatasociety/fdp-contracts ethers

Usage

To work with local fdp-contracts docker image, execute the following command:

fdp-play start --detach --blockchain-image fairdatasociety/fdp-contracts-blockchain $BEE_VERSION

NOTE: it will spin up the whole fdp environment for you with running Bee clients

ENS

To interact with Ethereum Name Service (ENS), import and instantiate the ENS class. The ENS class can be configured with predefined configurations or with a custom one. Currently, the only predefined configuration is for the localhost envirnoment, which means it will use the swarm-test-blockchain image running locally on http://localhost:9545 address.

Predefined configurations can be fetched using the getEnvironmentConfig function.

import { ENS, Environments, getEnvironmentConfig } from '@fairdatasociety/fdp-contracts'

const ens = new ENS(getEnvironmentConfig(Environments.LOCALHOST))

To use custom configuration, provide an instance of Environment type, or modify some of the predefined configurations:

import { ENS, Environments, getEnvironmentConfig, Environment } from '@fairdatasociety/fdp-contracts'

const customConfig: Environment = {
  ...getEnvironmentConfig(Environments.LOCALHOST),
  rpcUrl: 'www.example.com',
}

const ens = new ENS(customConfig)

Here is an example how to interact with ENS:

import { ENS } from '@fairdatasociety/fdp-contracts'

async function example() {
  const ens = new ENS() // Default configuration is for localhost
  const username = 'example'

  const isUsernameAvailable = await ens.isUsernameAvailable(username)

  console.log(`Username ${username} is available: ${isUsernameAvailable}`)
}

For methods that require transactions, a signer must be provided. Signer can be specified when creating an object of the ENS class, or later by calling the connect method. Signer can be a hex string of a private key, or an ethers.js signer.

import { Wallet } from 'ethers'
import { ENS } from '@fairdatasociety/fdp-contracts'

async function example() {
  const ens = new ENS()
  const wallet = new Wallet('0x...', ens.provider)

  ens.connect(wallet)

  const address = await wallet.getAddress()
  const username = 'example'

  await ens.registerUsername(username, address, wallet.publicKey)

  console.log(`Username ${username} successfully registered.`)
}

Development

To compile the library in watch mode:

npm start

To build the library:

npm run build

Local installation

The library can be linked, so it can be imported as a node module from another local project. First, inside this directory run:

npm link

Then in root directory of another project, the library can be installed with:

npm link @fairdatasociety/fdp-contracts

Tests

To automatically start a fdp-contracts container, build the library and run tests:

./scripts/test.sh

Tests are separated into unit and integration tests to the test/unit and test/it directorties, respectively.

In order to run integration tests, a container with FDP contracts must be started first. Also the librarry should be built. Then, tests are executed using the command:

npm run test:integration

To run both tests at once:

npm test