0.2.6 • Published 2 years ago

@interplanetary-lab/smart-contracts-ethers-js v0.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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');
0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago