0.1.3 • Published 2 years ago

@interplanetary-lab/smart-contracts-hooks v0.1.3

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

Smart Contracts Hooks

Interplanetary Lab's smart contract binding libraries for React hooks.

Table of Contents

Overview

Installation

$ npm install @interplanetary-lab/smart-contracts-hooks

Usage

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

import { useERC721RoundsData } from '@interplanetary-lab/smart-contracts-hooks';

//...
const {
  roundsState,
  activeRounds,
  nextRounds,
  syncRounds,
  lastUpdate,
} = useERC721RoundsData({ endpoint: '/api/rounds', syncInterval: 60 });

Documentation

Rounds

useERC721RoundsData and useERC1155RoundsData

Hooks allowing to get all rounds data in live.

The differences between useERC721RoundsData and useERC1155RoundsData are:

  • The content of the round type (ERC721Round or ERC1155Round)
  • totalSupply for useERC1155RoundsData is an object with tokenId as key

Options

import { useERC721RoundsData } from '@interplanetary-lab/smart-contracts-hooks';

const options: {
  /** The endpoint path that return all data of the contract */
  endpoint?: string,

  /** Number of seconds to wait between each data synchronization (0 if only one sync) */
  syncInterval?: number,

  /** Function called on each sync data with the API */
  onSyncData?: (data: never) => void,
} = {};

const roundsData = useERC721RoundsData(options);

Notes:

Returned states

import { useERC721RoundsData } from '@interplanetary-lab/smart-contracts-hooks';

const {
  /** The contract total supply */
  totalSupply,

  /** Current round state */
  roundsState,

  /** All fetched rounds updated with `syncData` */
  rounds,

  /** All active rounds sort by price (cheapest to most expensive) */
  activeRounds,

  /** All next rounds sort by startTime (closest to the farthest) */
  nextRounds,

  /** All past rounds sort by startTime (closest to the farthest) */
  pastRounds,

  /** Last time that all rounds have been updated */
  lastUpdate,

  /** Sync all data from the api */
  syncData,
} = useERC721RoundsData(options);
0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago