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

@interplanetary-lab/smart-contracts-ethers-js

v0.2.6

Published

Interplanetary Lab's smart contract binding libraries with Ethers.js

Downloads

3

Readme

Smart Contracts Ethers.JS

Interplanetary Lab's smart contract binding libraries with Ethers.js.

Table of Contents

Overview

Installation

$ npm install @interplanetary-lab/smart-contracts-ethers-js

Usage

Once installed, you can use the contracts in the library by importing them:

import { ethers } from 'ethers';
import { ERC721RoundsData } from '@interplanetary-lab/smart-contracts-ethers-js';

const provider = new ethers.providers.JsonRpcProvider('defaultRpcUrl');
const roundsData = new ERC721RoundsData({
  address: 'contractAddress',
  provider,
});

const allRounds = await roundsData.getRounds();
const { rounds, totalSupply } = await roundsData.getAllData();

Documentation

Rounds

ERC721RoundsData and ERC1155RoundsData

Constructor

You can instantiate the ERC721RoundsData or ERC1155RoundsData with:

  • The contract address and a ethers.js provider
import {
  ERC721RoundsData,
  ERC1155RoundsData,
} from '@interplanetary-lab/smart-contracts-ethers-js';

const roundsDataForERC721 = new ERC721RoundsData({
  address: 'contractAddress',
  provider,
});

const roundsDataForERC1155 = new ERC1155RoundsData({
  address: 'contractAddress',
  provider,
});
  • Directly with an existing contract instance
import { MyERC1155__factory } from '../../types/ethers-contracts';
import { ERC1155RoundsData } from '@interplanetary-lab/smart-contracts-ethers-js';

const contract = MyERC1155__factory.connect(address, provider);

const erc1155RoundsData = new ERC1155RoundsData({ contract });

Get rounds

Get all sanitized rounds data, filtered and typed with ERC721Round or ERC1155Round.

const allRounds = await roundsData.getRounds();

Verify signature

You can check if your signature data fit with your smart contract. Allows you to predict in advance that a private mint will not work and have more information than the revert of the contract.

Throw error like The signature is expired or The signature was not generated for the correct [contract|network|round|wallet].

import { ERC1155RoundSignData, ERC1155Round } from '@interplanetary-lab/smart-contracts-ethers-js';

try {

  let currentRound: ERC1155Round;
  let sigData: ERC1155RoundSignData;
  // ...
  // Get `sigData` from an api
  // ...
  await erc1155RoundsData.checkSignature(currentRound, account, sigData);
} catch (error: Error) {
  console.error(error);
}

Rounds state and sorts

Test state You can verify if a given round is start, active, next, past...

import {
  ERC721Round,
  ERC1155Round,
  isRoundStart,
  isRoundEnded,
  isRoundActive,
  isRoundNext,
} from '@interplanetary-lab/smart-contracts-ethers-js';

let round: ERC1155Round | ERC721Round;
// ...

const isStart = isRoundStart(round);
const isEnded = isRoundEnded(round);
const isActive = isRoundActive(round);
const isNext = isRoundNext(round);

Rounds filtered by state You can get an array of filtered rounds according to their condition.

import {
  ERC721Round,
  ERC1155Round,
  getActiveRounds,
  getNextRounds,
  getPastRounds,
} from '@interplanetary-lab/smart-contracts-ethers-js';

let rounds: ERC1155Round[] | ERC721Round[];
// ...

/// rounds started and not ended
const activeRounds = getActiveRounds(rounds);

/// rounds that have not yet started
const nextRounds = getNextRounds(rounds);

/// rounds that are finished
const pastRounds = getPastRounds(rounds);

// or

/// Get all at once (more optimized)
const { activeRounds, nextRounds, pastRounds } = getRoundsByState(rounds);

Rounds sorted You can get sort an array of rounds.

import {
  ERC721Round,
  ERC1155Round,
  sortRoundsByStartTime,
  sortRoundsByPrice,
  sortRoundsBy,
} from '@interplanetary-lab/smart-contracts-ethers-js';

let rounds: ERC1155Round[] | ERC721Round[];
// ...

/// sort rounds by startTime
const roundsByStartTime = sortRoundsByStartTime(rounds, 'asc');

/// sort rounds by price
const roundsByPrice = sortRoundsByPrice(rounds, 'desc');

/// sort rounds by a given BigNumber key
const customSorted = sortRoundsBy('totalMinted', rounds, 'asc');