Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Nft

This class supports creating AINFT object, searching AINFTs and things about NFTs.
Do not create it directly; Get it from AinftJs instance.

Hierarchy

Index

Constructors

  • new Nft(baseUrl: string, route: null | string, ain: default, ainize?: default): Nft

Properties

ain: default

The Ain object for sign and send transaction to AIN blockchain.

ainize?: default

The Ainize object for send request to AIN blockchain.

baseUrl: string = ''

The base url of api server of AINFT Factory.

route: string

The subpath of api server request url.

Methods

  • Create AINFT object.

    Parameters

    Returns Promise<{ ainftObject: Ainft721Object; txHash: string }>

    Transaction hash and AINFT object instance.

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs('YOUR-PRIVATE-KEY');
    ainftJs.nft.create('nameOfAinftObject', 'symbolOfAinftObject')
    .then((res) => {
    const { txHash, ainftObject } = res;
    console.log(txHash); // 0x...
    console.log(ainftObject.id); // 0x...
    console.log(ainftObject.appId); // ainft721_0x...
    })
    .catch((error) =>{
    console.log(error);
    });
  • Get AINFT object instance by ainftObjectId.

    Parameters

    • ainftObjectId: string

      The ID of AINFT object.

    Returns Promise<Ainft721Object>

    Returns the AINFT object corresponding to the given ID.

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs('YOUR-PRIVATE-KEY');
    ainftJs.nft.get('YOUR-AINFT-OBJECT-ID')
    .then((res) => {
    const ainftObject = res;
    console.log(ainftObject.appId);
    })
    .catch((error) => {
    console.log(error);
    })
  • Get AINFTs by user address.

    Parameters

    • address: string

      The ID of AINFT object.

    • Optional limit: number

      Sets the maximum number of NFTs to retrieve.

    • Optional cursor: string

      Optional cursor to use for pagination.

    Returns Promise<AinftTokenSearchResponse>

    Returns AINFTs.

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs('YOUR-PRIVATE-KEY');
    ainftJs.nft.getAinftsByAccount('TOKEN-OWNER-ADDRESS')
    .then((res) => {
    const { nfts, isFinal, cursor } = res;
    console.log(nfts); // list of nft information.
    })
    .catch((error) => {
    console.log(error);
    })
  • Get AINFTs by AINFT object id.

    Parameters

    • ainftObjectId: string

      The ID of AINFT object.

    • Optional limit: number

      Sets the maximum number of NFTs to retrieve.

    • Optional cursor: string

      Optional cursor to use for pagination.

    Returns Promise<AinftTokenSearchResponse>

    Returns AINFTs.

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs('YOUR-PRIVATE-KEY');
    ainftJs.nft.getAinftsByAinftObject('YOUR-AINFT-OBJECT-ID', 5)
    .then((res) => {
    const { nfts, isFinal, cursor } = res;
    console.log(nfts); // list of nft information.
    })
    .catch((error) => {
    console.log(error);
    })
  • register(ainftObjectId: string): Promise<void>
  • Register AINFT object to factory server. If functions such as mint, transfer, or search do not work well after executing the create function, try executing this function.

    Parameters

    • ainftObjectId: string

      The ID of AINFT object.

      import AinftJs from '@ainft-team/ainft-js';

      const ainftJs = new AinftJs('YOUR-PRIVATE-KEY');
      ainftJs.nft.register('YOUR-AINFT-OBJECT-ID')
      .catch((error) => {
      console.log(error);
      })

    Returns Promise<void>

  • Searches for AINFT objects created on the AIN Blockchain. This method accesses public data only and does not require signature in the requests.

    Parameters

    Returns Promise<AinftObjectSearchResponse>

    Returns searched AINFT objects.

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs();
    const params = {
    userAddress: '0x...',
    name: '...',
    symbol: '...',
    slug: '...',
    limit: 5,
    cursor: '...'
    }
    ainftJs.nft.searchAinftObjects(params)
    .then((res) => {
    const { ainftObjects, isFinal, cursor } = res;
    console.log(ainftObjects); // list of ainftObject information.
    })
    .catch((error) => {
    console.log(error);
    })
  • Searches for AINFTs on the ain blockchain. This method accesses public data only and does not require signature in the requests.

    Parameters

    Returns Promise<AinftTokenSearchResponse>

    Returns searched AINFTs

    import AinftJs from '@ainft-team/ainft-js';

    const ainftJs = new AinftJs();
    const params = {
    userAddress: '0x...',
    name: '...',
    symbol: '...',
    limit: 5,
    cursor: '...',
    tokenId: '...'
    }
    ainftJs.nft.searchNfts(params)
    .then((res) => {
    const { nfts, isFinal, cursor } = res;
    console.log(nfts); // list of nfts information.
    })
    .catch((error) => {
    console.log(error);
    })
  • sendFormRequest(method: POST | PUT, trailingUrl: string, stringFields: {}, fileFields: {}): Promise<any>
  • Sends request that include form to api server of AINFT Factory. Used to upload asset data.

    Parameters

    • method: POST | PUT

      The method of Http request.

    • trailingUrl: string

      The suffix of request url.

    • stringFields: {}

      The string fields of form.

      • [key: string]: string
    • fileFields: {}

      The file fields of form.

      • [key: string]: { buffer: Buffer; filename: string }
        • buffer: Buffer
        • filename: string

    Returns Promise<any>

    Returns response of api request.

  • sendRequest(method: HttpMethod, trailingUrl: string, data?: Record<string, any>): Promise<any>
  • Sends request to api server of AINFT Factory. Authenticate by signing data.

    Parameters

    • method: HttpMethod

      The method of Http request.

    • trailingUrl: string

      The suffix of request url.

    • Optional data: Record<string, any>

      The data to be included in the api request.

    Returns Promise<any>

    Returns response of api request.

  • sendRequestWithoutSign(method: HttpMethod, trailingUrl: string, data?: Record<string, any>, headers?: AxiosRequestHeaders): Promise<any>
  • Sends request to api server of AINFT Factory. Used when authentication is not required.

    Parameters

    • method: HttpMethod

      The method of Http request.

    • trailingUrl: string

      The suffix of request url.

    • Optional data: Record<string, any>

      The data to be included in the api request.

    • Optional headers: AxiosRequestHeaders

      The headers of Http api request.

    Returns Promise<any>

    Returns response of api request.

  • setBaseUrl(baseUrl: string): void
  • signData(data: any): string | Promise<string>
  • Sign the data with the private key that the user has registered.

    Parameters

    • data: any

      The data to sign.

    Returns string | Promise<string>

    Returns signature string.

Generated using TypeDoc