Skip to content

nervina-labs/cota-sdk-js

Repository files navigation

cota-sdk-js

License CI NPM

JavaScript SDK for CoTA.

CoTA Docs

Installation

$ npm i @nervina-labs/cota-sdk
# or
$ yarn add @nervina-labs/cota-sdk

Prerequisites

CoTA SDK needs to run the services as blow:

  • CKB Node: Nervos CKB Node
  • CKB Indexer: Fetch live cells and transactions with filters
  • CoTA Syncer: Parse CoTA witness SMT data from CKB blockchain history transactions and save it to the mysql database
  • CoTA Registry Aggregator: Generate SMT info using the data from the database for registry and provide RPC APIs
  • CoTA Aggregator: Generate SMT info using the data from the database for CoTA NFT actions and provide RPC APIs

The above services are valid only when synced to the latest block and we strongly suggest to run the services in mainnet by yourself.

Public ckb node url and ckb indexer url as blow can be used to develop and test

# mainnet:
https://mainnet.ckbapp.dev/rpc       --->  ckb mainnet node rpc
https://mainnet.ckbapp.dev/indexer   --->  ckb mainnet indexer rpc

# testnet:
https://testnet.ckbapp.dev/rpc       --->  ckb testnet node rpc
https://testnet.ckbapp.dev/indexer   --->  ckb testnet indexer rpc

Public aggregator rpc url as blow can be used to develop and test

# mainnet:
https://cota.nervina.dev/mainnet-aggregator            --->  cota aggregator rpc
https://cota.nervina.dev/mainnet-registry-aggregator   --->  cota registry aggregator rpc

# testnet:
https://cota.nervina.dev/aggregator                    --->  cota aggregator rpc
https://cota.nervina.dev/registry-aggregator           --->  cota registry aggregator rpc

CoTA NFT Flow

                     Register CoTA cell firstly
1. Alice & Bob & Tom ----------------------------------> Alice CoTA cell & Bob CoTA cell & Tom CoTA cell

          Define CoTA NFT               Mint CoTA NFT A to receivers
2. Alice -----------------------> NFT A -----------------------------------> Receivers (Bob)

                    Claim NFT A                                  Withdraw NFT A to Tom
       Action1 |-------------------------> Bob hold NFT A now ----------------------------------> Bob doesn't hold NFT A now
      |             Transfer NFT A to Tom
3. Bob Action2 |-----------------------------------> Bob doesn't hold NFT A now
      |           Update CoTA NFT A information
       Action3 |-----------------------------------> Bob hold CoTA NFT A with new information

                    Claim NFT A                                 Withdraw NFT A to other receivers
        Action1 |-------------------------> Tom hold NFT A now ----------------------------------> Tom doesn't hold NFT A now
4. Tom |         Transfer NFT A to other receivers
        Action2 |-----------------------------------> Tom doesn't hold NFT A now

  • Registry: Every address should be registered firstly
  • Define: The issuer can define a collection NFTs with total/name/description/image etc.
  • Mint: The issuer mint the defined NFTs to the receivers (withdraw to the receivers actually)
  • Claim: The receiver can claim the NFT from the mint, and now the receiver hold the NFT
  • Update: The holder of NFT can update the information (characteristic/state etc.)
  • Withdraw: The holder of NFT can withdraw the NFT to any other CKB address
  • Transfer: To simplify, transfer combines the claim and withdraw into one operation. The receiver can claim the NFT from the mint and withdraw the same NFT to others in a transaction.

Examples