0.0.1 • Published 1 year ago

@hashed-alejandro/afloat-client v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Afloat Client Api

This client api is used to provide methods to interact with gatedMarketplace, uniques and fruniques pallets and go through Afloat specific flow.

To install the afloat-client-api, run the following command:

npm i --save @jmgayosso/afloat-client or yarn add @jmgayosso/afloat-client

To connect to 'hashed chain' through Hashed Confidential Docs we must import HCD package hashed-confidential-docs-client that handles the connection and provides methods to sign tx, login, requestUsers from polkadotJS and sign and verify messages.

Setup

To install hcd run the following command.

npm i --save @smontero/hashed-confidential-docs or yarn add @smontero/hashed-confidential-docs

The following is an example of basic config to create HCD instance, please see HCD documentation to more configs.

import {
  HashedConfidentialDocs,
  Polkadot,
  LocalAccountFaucet,
  BalancesApi
} from '@smontero/hashed-confidential-docs'
import { Keyring } from '@polkadot/api'

const _polkadot = new Polkadot({ wss: chainURI, appName })
await _polkadot.connect()

const keyring = new Keyring()
const faucet = new LocalAccountFaucet({
  balancesApi: new BalancesApi(this._polkadot._api, () => {}),
  signer: keyring.addFromUri(this._signer, {}, 'sr25519'),
  amount: 1000000000
})
const _hcd = new HashedConfidentialDocs({
  ipfsURL: _ipfsURL,
  polkadot: _polkadot,
  faucet,
  ipfsAuthHeader: _ipfsAuthHeader
})

HCD is requeried to create an instance of AfloatApi, this class provides the following methods: createAssets, getAllAssetsInCollection, getAssets, getFromIpfs.

import { AfloatApi } from '@jmgayosso/afloat-client'

const ipfsURL = `Basic ${Buffer.from(`${process.env.IPFS_PROJECT_ID}:${process.env.IPFS_PROJECT_SECRET}`).toString('base64')}`

const afloatApi = new AfloatApi({
  ipfsURL: process.env.IPFS_URL,
  ipfsAuthHeader,
  polkadot: _polkadot
})

Once an instance of AfloatApi is created, the following methods can be accessed.

Methods

  • createAsset: Create a new frunique/NFT asset.

    Params

    • @param {u64} collectionId Collection ID used in the uniques pallet; represents a group of Uniques
    • @param {u64} assetId optional Asset ID used in the uniques pallet; represents a single asset. If not provided, the next available unique ID will be automatically selected.
    • @param {Object} uniquesPublicAttributes mapping of key/value pairs to be set in the public metadata in the uniques pallet
    • @param {Object} saveToIPFS payload and/or files to be saved to IPFS, and the resulting CIDs are added to the uniquesPublicMetadata, anchoring the data to the NFT.
    • @param {Object} cidFromHCD cidFromHCD cid got from the ConfidentialDocs API
    • @param {Function} subTrigger Function to trigger when subscrsption detect changes

      Example

    await afloatApi.createAsset({
      "collectionId": undefined, 
      "assetId": 0,
      "uniquesPublicAttributes": {
          "Lorem ": "Plaintext"
      },
      "saveToIPFS": {
          "data": {
              "label2": "ipfs plain"
          },
          "files": {
              "label 3": "cid"
          }
      },
      "cidFromHCD": {
          "data": {
              "label4": "cid saved on HCD"
           },
          "files": {
              "label5": "cid saved on HCD"
           }
      },
      admin
    })

    Notes

    To save a file in HCD you must go from HCD Documentation

  • getAllAssetsInCollection: Get all assets in collection.

    Params

    • @param {u64} collectionId Collection ID used in the uniques pallet; represents a group of Uniques
    • @param {u64} startKey Asset ID, index, or key to start the query
    • @param {int} pageSize maximum number of assets to retrieve per request
    • @param {Function} subTrigger Function to trigger when subscription detect changes

      Example

    await afloatApi.getAllAssetsInCollection({
      collectionId,
      startKey,
      pageSize
    })
  • getAsset: Get a specific asset by collectionId.

    Params

    await afloatApi.getAsset({ collectionId, instanceId })
  • getFromIPFS: Get Text or File from IPFS.

    Params

    • @param {String} cid Unique IPFS identifier

      Example

    await afloatApi.getFromIPFS(cid)