NRC-721 - An extensible & modular NFT implementation for the Nervos Network
  • NRC-721
  • Quick Start
    • Rust
    • SDK
  • Reference
    • Cells
      • Factory Cell
      • Token Cells
Powered by GitBook
On this page
  • Installing and setup
  • Minting a Factory Cell
  1. Quick Start

SDK

A Javascript SDK to simplify integration into Dapps

PreviousRustNextCells

Last updated 3 years ago

Having defined a standard for NFTs allows creating pre-built tools to interact with them. The SDK developed by our team serves this purpose, it allows creating, reading, and managing factory Cells and NFTs in a simple way, so Dapps developers can adopt our standard without the need to get into the transaction implementation details. The source code along with examples of usage are available in .

Installing and setup

The SDK is available on npm package manager, it can be installed by running:

npm install @rather-labs/nrc-721-sdk

To run the examples available in the repository a testnet address and private key will be needed, they can be generated using this . We will also need some ckb to create the cells, on testnet we can get this ckb by inserting our address in this .

The examples are set up to connect to a node and indexer running locally, a local testnet or dev node can be run following the instructions , and to run a local indexer. Nervos also maintains a public testnet node and indexer that can be used just by setting the URLs:

nodeUrl = "http://3.235.223.161:18114";
indexerUrl = "http://3.235.223.161:18116";

Minting a Factory Cell

To be able to create NFTs we first need to mint a factory cell, that will be used to mint NFTs from it and store common info, so it acts as a collection. Unless some custom functionality is needed, the factory can be created using the Type ID logic that is built into Nervos blockchain, so no contract deployment is needed.

The factory can be minted just by indicating the basic info it will contain:

const { rawTransaction, typeScript, usedCapacity } = 
  await factoryCell.mint({
    name: "Test token factory",
    symbol: "TTF",
    baseTokenUri: "http://testtoken.com",
    sourceAddress: OWNER_ADDRESS,
    targetAddress: OWNER_ADDRESS,
    fee: 0.0001,
  });
  
const { rawTransaction, nftTypeScript, usedCapacity } = 
  await nftCell.mint({
    nftContractTypeScript,
    factoryTypeScript,
    sourceAddress: OWNER_ADDRESS,
    targetAddress: OWNER_ADDRESS,
    fee: 0.0001,
    data: {
      someKey: "SomeValue",
      anotherKey: "AnotherValue",
    },
});
Nft Token Id:  d9ae00e88a7c2c701df1a7ee410b05a67c0a13fc50bfa0bbe05553d4ddb7e75e
Nft Token URI:  
http://testtoken.com/d9ae00e88a7c2c701df1a7ee410b05a67c0a13fc50bfa0bbe05553d4ddb7e75e
Nft Cell Data:  { someKey: 'SomeValue', anotherKey: 'AnotherValue' }
Factory Data:  {
  name: 'Test token factory',
  symbol: 'TTF',
  baseTokenUri: 'http://test-token.com'
}

the full example code can be found . After minting our factory cell we will have its typeScript that will be used to identify our cell in the blockchain and will be needed to mint our NFTs.

Now we have our factory and from the previous section we should also have a deployed contract to govern our NFTs, so we are ready to mint our tokens, we just need the typeScript of our contract cell. We have also deployed our base NRC-721 contract in the testnet and is available to anyone to test the SDK integration, you can find its typeScript in our .

We are now ready to mint our NFTs using , indicating our contract and factory typeScripts. A data object can also be included, by default it will be serialized using JSON and stored in the data part of the NFT cell:

The minted token can be retrieved from the blockchain using the SDK as shown in . We will be able to get all the info for the token and factory, so we can now use it on our Dapp:

Github
tool
faucet
here
here
here
Github
this example
this example