2.9.0 • Published 11 months ago

@kanji-world/react-sdk v2.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Status GitHub Issues GitHub Pull Requests License


🧐 About

With Kanji, you can create and customize your NFTs collections and monitor them in the long. This nom package is meant to enable your developers to integrate the sale of your collection directly on your own website. It is written in Typescript, so is usable in any Javascript front end format. This is only a V1, much more to come next, enjoy!

🏁 Getting Started

Prerequisites

You will need start to install nodeJs and npm library.

Installing

The installation of the npm package is very simple, just open a terminal window in the root of your project and copy-paste the following lines:

npm i @kanji-world/react-sdk
//or
yarn add @kanji-world/react-sdk
//or
pnpm i @kanji-world/react-sdk

🎈 Usage

To use our package, your first need to import the kanji library:

import { KanjiSDK } from '@kanji-world/react-sdk';

As the first you need to instantiate the SDK by using following line:

///@dev instanciate kanjiSDK
const kanjiSDK = KanjiSDK.getInstance();

To communicate and load revelant datas for your customer, please provide your API KEY (no critical or private datas are loaded, you can use this API key in your front end code):

///@dev set your api key for return good collection and call API
kanjiSDK.setApiKey(api_key);

CONNECTION


connectToKanjiAccount

To connect your customers to the blockchain you need to use WEB3 modal, this will enable your customer to connect throw the wallet of their choice:

  • metamask
  • torus
  • portis
  • walletConnect
  • ledger

To open the modal and perform connection please use the following line of code:

//if getNewSignature === true your provider (metamask or other) gonna request a signature and if false it gonna search if signature is stored and valid
kanjiSDK.connectWeb3(getNewSignature = true):jwt;

To disconnect your customer, use :

//@dev disconnect user
kanjiSDK.disconnectWeb3();

WEB2 CALLS

The following methods can be called, once you a mentioned your API key, in kanjiSDK.setApiKey(api_key) and grants you access to your releavant collections datas

COLLECTIONS

To get all of yours created collections you can use the following method:

  /**
   * Call api route /sdk/collections/ {GET} to get Lists of Collections of current brand connected
   * @returns {Promise<[ICollection]>} Return an array of collection linked by api_key
   * @category Collections
   */
  async kanjiSDK.getCollections(): Promise<[ICollection]>

  /**
   * Call api route /sdk/collections/ids {GET} to get Lists of Collections of current brand connected
   * @returns {Promise<[string]>} Return an array of ids collection linked by api_key
   * @category Collections
   */
  async getCollectionIds(): Promise<[string]>

  /**
   * Call api route /sdk/collections/names {GET} to get Lists of Collections of current brand connected
   * @returns {Promise<[string]>} Return an array of names collection linked by api_key
   * @category Collections
   */
  async getCollectionNames(): Promise<[string]>

  /**
   * Call api route /sdk/tokens/:collectionId {GET} to get Collection by id's collection
   * @param {ICollection} collection Collection interface you want to get tokens
   * @returns {Promise<[IFormattedToken]>} Return an object error or array of tokens interface
   * @category Collections
   */
  async getTokensByCollectionId(
    collection: ICollection
  ): Promise<[IFormattedToken]>

  /**
   * Call api route /sdk/tokens/:collectionName {GET} to retrieve tokens by name's collection
   * @param {ICollection} collection Collection interface you want to get tokens
   * @returns {Promise<[IFormattedToken]>}
   * @category Collections
   */
  async getTokensByCollectionName(
    collection: ICollection
  ): Promise<[IFormattedToken]> {
    return Fetch(`/sdk/tokens/` + collection.name, 'GET', {});
  }

CLAIMCONDITIONS

The follow method enables you to get all the sell phases (AKA claimConditions) that you created on Kanji platform to enable your customers to claim tokens of given collection for a certain price and conditions.

  /**
   * Call api route /sdk/claim-condtions/ {GET} to return array of claim condition in collection
   * @param {ICollection} collection Collection you want to interact
   * @returns {Promise<[IFormattedClaimCondition]>} Array of claim condition in collection
   */
  async getClaimConditions(
    collection: ICollection
  ): Promise<[IFormattedClaimCondition]>

To get the next active claim condition, you can use the following web3 method:

  /**
   * Call api route /sdk/next-claim-condtions/ {GET} to return next claim condition in collection or error if no current sales
   * @param {ICollection} collection Collection you want to interact
   * @returns {Promise<IFormattedClaimCondition>} Next claim condition in collection
   */
  async getNextClaimCondition(
    collection: ICollection
  ): Promise<IFormattedClaimCondition>

To get the current active claim condition, you can use the following web3 method:

  /**
   * Call api route /sdk/current-claim-condtions/ {GET} to return current claim condition in collection or error if no current sales
   * @param {ICollection} collection Collection you want to interact
   * @returns {Promise<IFormattedClaimCondition>} Current claim condition in collection
   */
  async getCurrentClaimCondition(
    collection: ICollection
  ): Promise<IFormattedClaimCondition>

WEB3 CALLS

The follow methods all require your customers to be connected to the blockchain, because they are meant to communicate with it

CLAIM

For your customer to be able to claim an nft of a specific collection, you can use the following web3 method:

  /**
   * Claim a quantity of token lazy minted and listed in claimCondition
   * @param {ICollection} collection Interface Collection with which you can interact
   * @param {number} quantity Quantity of token you want to claim
   * @param {number} tokenId Token Id for erc1155 or cardIdToRedeem
   * @returns {Promise<Record<string, string> | IErrorKanjiSmartContract>} Return the hash of the performed transaction on the blockchain
   * @category KANJIDROPERC721A
   */
  async claim(
    collection: ICollection,
    quantity: number,
    tokenId = 0
  ): Promise<Record<string, string> | IErrorKanjiSmartContract>

INTERFACES

//interface type of collection required to call some function
import {
  IFormattedToken,
  IFormattedClaimCondition,
  IErrorKanjiSmartContract,
  IClaimReturn,
} from '@kanji-world/react-sdk';

export interface IFormattedToken {
  _id: string;
  name: string;
  description: string;
  properties: any;
  thumbail: string;
  tokenId: number;
  collectionId: string;
  collectionName: string;
}

export interface IFormattedClaimCondition {
  name?: string;
  startTimestamp: number;
  endTimestamp: number;
  maxClaimableSupply?: number;
  supplyClaimed?: number;
  pricePerToken?: string;
  currency?: string;
}

export interface IErrorKanjiSmartContract {
  errorFunction: any;
  decoded: any;
  lastError: any;
}

export interface IClaimReturn {
  enrichedTokens: IToken[];
  claimer: IUser;
}
2.2.1

1 year ago

2.2.0

1 year ago

2.4.1

12 months ago

2.4.0

12 months ago

2.6.1

11 months ago

2.6.0

12 months ago

2.8.1

11 months ago

2.8.0

11 months ago

2.3.0

1 year ago

2.5.0

12 months ago

2.7.0

11 months ago

2.9.0

11 months ago

2.8.2

11 months ago

1.37.0

1 year ago

1.33.1

1 year ago

1.39.1

1 year ago

1.39.0

1 year ago

1.21.0

1 year ago

2.0.0

1 year ago

1.25.0

1 year ago

1.23.0

1 year ago

1.23.1

1 year ago

1.29.0

1 year ago

1.29.1

1 year ago

1.27.0

1 year ago

1.32.0

1 year ago

1.32.1

1 year ago

1.30.0

1 year ago

1.30.1

1 year ago

1.36.0

1 year ago

1.36.1

1 year ago

1.34.0

1 year ago

1.32.2

1 year ago

1.38.0

1 year ago

1.38.1

1 year ago

2.1.1

1 year ago

1.22.0

1 year ago

2.1.0-v1.1

1 year ago

2.1.0

1 year ago

1.20.0

1 year ago

1.26.0

1 year ago

1.24.0

1 year ago

1.28.0

1 year ago

1.33.0

1 year ago

1.31.0

1 year ago

1.0.1

1 year ago

1.19.0

1 year ago

1.19.2

1 year ago

1.19.1

1 year ago

1.15.0

1 year ago

1.14.1

1 year ago

1.13.2

1 year ago

1.2.0

1 year ago

1.14.0

1 year ago

1.13.1

1 year ago

1.1.0

1 year ago

1.13.0

1 year ago

1.12.0

1 year ago

1.17.2

1 year ago

1.18.0

1 year ago

1.17.1

1 year ago

1.17.0

1 year ago

1.16.0

1 year ago

1.15.1

1 year ago

1.14.2

1 year ago

1.13.3

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.17.3

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.3.3

1 year ago

1.5.0

1 year ago

1.3.2

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.11.0

1 year ago

1.10.0

1 year ago

1.0.0

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago