chaincerts

FREE
By ChainCerts API | Updated месяц назад | eCommerce
Popularity

0 / 10

Latency

893ms

Service Level

0%

Health Check

N/A

Back to All Tutorials (3)

How to setup NFT marketplace using chaincerts endpoints ?

Non Fungible tokens (NFTs) are taking the world by storm. People have begun to buy and sell digital items in significant numbers on marketplaces. Creating a marketplace from scratch is time consuming and requires a good background knowledge about blockchain. Using Chaincerts APIs can help you create an NFT marketplace in an easy and straightforward way.
Our APIs provide you with:

  • An authentication module for signup, login, password handling, profile updating, etc.
  • A NFT creator module for uploading NFT, minting NFTs to the Polygon blockchain, transferring NFTs to other users, selling NFTs, etc.
  • A collector module that includes listing the available NFTs, buying NFTs using credit card or cryptocurrency, listing the user collection, etc.

How to use RapidAPI to find endpoints details and code snippets?

Step 1: Find your API endpoint
In How to build your own NFT sales store using Rapid API and Chaincerts section we will go through the endpoints required to build a basic NFT marketplace. To find the parameters for each endpoint and code snippets sample go to Rapid API website and look for chaincerts, under endpoints section, in the search endpoints box type the endpoint name. For example, to sign up a new user we will use the signup API.

1.png

Step 2: Fill out the required parameters
In the middle section we find a detailed description of the selected endpoint with the scenarios when errors occur. Next we find a dropbox where you can choose the Rapid API account and Rapid API application you wanna use. Then we found Header parameters where X-RapidAPI-Key and X-RapidAPI-Host will be automatically filled. Most APIs require an authorization parameter, our APIs use Bearer authorization. In the authorization parameter add bearer keyword before TokenID received on login. In the final dropdown menu we find the required and optional parameters.
In signup For example, the required parameters are the email, first name, user role, password and username. If the user is NFT creator/ marketplace owner please provide the role as Owner, and if the user is a NFT collector please set the role to client. The optionals are last name, phone number and organization name.
3.png

Step 3: Test the API endpoint
After filling the parameters, click Test Endpoint button, In the results panel you will see something like this:

4.png

The most important field is the id as we are going to need it for most of the APIs. You can also find a response sample without testing the API by clicking on Example Responses button the the last panel.

5.png

Step 4: Find code snippet
Rapid API also provides code snippets in most common languages. React application uses javaScript. Click on the Code Snippets button in the left panel and select Javascript Axios. Code snippets will appear with all the parameters filled from the previous step.

7.png

To see a curl example, select shell and choose cURL option.

8.png
Conclusion
Using Rapid API allows you to discover the endpoints that we offer to build a NFT Marketplace in an easy way. We also provide detailed description, response sample and code snippet to facilitate the integration of the endpoints to your frontend. In the next session we are going to describe in detail the endpoints and the workflow to implement the NFT marketplace using chaincerts APIs.

How to build your own NFT sales store using Rapid API and Chaincerts?

Creator workflow
Step 1: signup

The first step is to sign up using the /api/users/singup. At signup a new user is created with the provided first name, last name, username, email, role and password. In case of email or username duplication an error will be raised. The associated role for NFT creators is Owner.

Step 2: Send verification code

Send verification code via email to confirm user email using /api/users/send-verification-code endpoint. User Id is required.

Step 3: Confirm email

Confirm email by sending the code received by email and the user id to /api/users/ConfirmVerificationCode endpoint. User Id is required.

Step 4: Confirm account for minting.

By default, the user status will be deactivated. In order to mint NFT you must verify your account by sending an email to info@app-scoop.com.

Step 4: Login

In order to use most of the rest APIs, authentication is required via /api/users/login endpoint by providing the user email and password. If login is successful a bearer token will be sent in the response that must be sent in the Authorization parameter. The word Bearer must be added before the token.

Step 5: Add money to the chaincerts wallet.

TBD

In order to see the history of transactions made to add money to your wallet use /api/users/getWalletTxs.

Step 6: Upload NFT

In order for a user with owner role to mint NFT, first the NFT must be uploaded to the aws server and to IPFS using pinata service via the endpoint /api/users/UploadFile. Metadata also can be provided to the API including: production year, type, category, subject, width, height, depth, unit (cm or inch), quantity, image hash, production place, stock details, location and date of issue. An example code snippet and response can be found in the endpoint section.

Step 7: Mint NFT.

In order to mint an NFT that is already uploaded, the user will be charged 1$ from their chaincerts wallet. So make sure to have enough balance before calling the following endpoints. To see the list of the uploaded files that are not minted yet call /api/users/getFilesUnverified.
There is two available endpoints to mint an NFT:

  • The first one is /api/users/uploadFileIntoBlockchainwithsqs that enable user to mint a single NFT by providing the image id to be minted and the user id. The file must be owned by the provided user id.
  • The second one is /api/users/uploadMultFileMultBatchwithsqs that enable user to mint multiple NFTs by providing an array of the images ids to mint, an array of quantity to mint for each image and the user id. All files must be owned by the provided user id. Using this endpoint will save you money as it only charges 1$ for all specified images.

If there is no error, the file/files will be sent to SQS queue SQS queue where the transaction will be processed to the blockchain.

Step 7: Transfer NFTs

In order to transfer a minted NFT, the user will be charged 1$ from their chaincerts wallet. So make sure to have enough balance before calling the following endpoints. To see the list of the owned minted files call /api/users/certMinted.
There is two available endpoints to mint an NFT:

  • The first one is /api/users/transferSinglewithsqs that enables the user to transfer a single NFT by providing the image id to be minted, the receiver id and the user id. The file must be owned by the provided user id.
  • The second one is /api/users/transferMultiplewithsqs that enable user to transfer multiple NFTs by providing an array of the images ids to transfer, an array of quantity to transfer for each image and the user id, password and the receiver id. All files must be owned by the provided user id. Using this endpoint will save you money as it only charges 1$ for all specified images.

If there is no error, the file/files will be sent to SQS queue SQS queue where the transaction will be processed to the blockchain.

NOTE: In order to transfer files to another user, the receiver must also have an account in chaincerts. The file will be transferred to the receiver public key generated when the user signup.

Step 8: Sell NFTs

The best option for selling NFT is to implement your own endpoints to sell NFTs and receive money to your own bank or crypto account, and use chaincerts transfer endpoints to transfer the ownership once money is received.

Step 9: Listing of owned NFTs

To check the list of owned files whether uploaded, minted, transfered or bought use /api/users/getfilesbyuser endpoint and provide your user id. In order to get all the details about a specific NFT use /api/users/getfilesbyid endpoint, and provide your user id and image id.

Step 10: Update the marketplace details

The minted NFTs that were put on sale will be sold in a marketplace specified for each owner. In order to update the store details that include: title, description, contract information, banner details, store details, store opening and ending date. Also to upload a file for marketplace logo and banner use /api/users/updateProfile endpoint.

Example: Transfer File to another user after minting

Let’s assume that Alice who has already an active account in chaincerts want to mint an NFT into polygon blockchain and then transfer it to Bob who does not have an account using chaincerts APIs.

First Alice needs to log in to her account in order to receive the bearer token required for authentication /api/users/login.

curl --request POST \
	--url https://chaincerts1.p.rapidapi.com/api/users/login \
	--header 'X-RapidAPI-Host: chaincerts1.p.rapidapi.com' \
	--header 'X-RapidAPI-Key: 9b13b8ba10msh3ec38b983be6540p12d5a5jsneb9afd55a64e' \
	--header 'content-type: application/x-www-form-urlencoded' \
	--data password=alice@123 \
	--data email=alice@gmail.com

From the response, save the user id and token as we are going to need them for the rest of the APIs.

{
    "status": true,
    "msg": "Login successfully",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MTA5NjgsImV4cCI6MTY2MDUxNDU2OH0.EzFwocti_i303Gshsl7dFL2uzDEbYdE7xDLnEo8TP5s",
    "data": {
        "userRole": "owner",
        "amount": 9997,
        "userStatus": "active",
        "store_opening_date": "2010-01-06T22:03:20.281Z",
        "store_ending_date": "2030-01-06T22:03:20.281Z",
        "phoneNumberVerified": "false",
        "twoFacAuthEnabled": "false",
        "isShippingAddressUS": false,
        "_id": "62f78c230af4b000190d6f4c",
        "firstName": "alice",
        "username": "aliceshop",
        "email": "alice@gmail.com",
        "verificationCode": 328742,
        "publicKey": "0x18d9b3fdBfb62AbACBE8487339eC1A3b99A82789",
        "createdDate": "2022-08-13T11:33:55.228Z",
        "__v": 0,
        "emailVerifiedAt": "2022-08-13T11:35:20.972Z",
        "organizationName": "aliceshop",
        "logo": "https://test-chaincerts.s3.amazonaws.com/undefined",
        "banner": "https://test-chaincerts.s3.amazonaws.com/undefined",
        "id": "62f78c230af4b000190d6f4c"
    }
}

Alice now needs to upload her NFT to the chaincerts and IPFS server using /api/users/uploadFile endpoint.
Alice already has enough balance in her wallet.

curl --location -g --request POST 'https://dev.chaincerts.org:3030/api/users/uploadFile?userId=62f78c230af4b000190d6f4c&imageHash=96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64&category=Alice%20NFT%20description&type=Digital%20art&subject=Alice%20NFT&quantity=1&attributes=[{%22value%22:%22Starfish%22,%22trait_type%22:%22Base%22},{%22value%22:%22Big%22,%22trait_type%22:%22Eyes%22},{%22trait_type%22:%22Generation%22,%22value%22:%2210%22,%22max_value%22:%22100%22,%22display_type%22:%22boost_number%22},{%22trait_type%22:%22Eyes%22,%22value%22:%2215%22,%22max_value%22:%22100%22,%22display_type%22:%22boost_number%22}]&productionYear=Sun%20Aug%2014%202022%2000:00:00%20GMT+0100%20(Central%20European%20Standard%20Time)&height=50&width=10&depth=10&unit=Cm&validUntil=2022-08-31&place=Montreal&location=Montreal&stockDetails=&dateofIssue=Sun%20Aug%2014%202022%2000:00:00%20GMT+0100%20(Central%20European%20Standard%20Time)' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDM5MzgsImV4cCI6MTY2MDUwNzUzOH0.6p1K55GRhydQGooyGSkUZlK8LzCq1GnadoPT_IQYDJ8' \
--header 'Cookie: connect.sid=s%3A25CQE9CKxok95I0yfP8PrTvSjbOJW4qJ.zs54%2BcYUlz%2BJYUelXPn%2FW1fH8hkLUIrKIc%2FbDQco%2FEw; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDMxMzYsImV4cCI6MTY2MDUwNjczNn0.ffzzpGCtH40Pk27PwJr69Kob_vZPXZnw4PosRHwZArg' \
--form 'file=@"/home/wejdene/Pictures/1125.jpg"'

The upload was successful and she receives the following response

{
    "status": true,
    "msg": "Certificate and metadata uploaded on IPFS successfully",
    "data": {
        "validUntil": "2022-08-31",
        "linkedTo": "None",
        "isOwned": "Yes",
        "events": [
            {
                "type": "Creation",
                "Msg": "New certificate is created"
            }
        ],
        "imageStatus": "Unverified",
        "forSaleStatus": false,
        "price": 0,
        "validForSaleFrom": "2010-01-06T22:03:20.281Z",
        "validForSaleUntil": "2030-01-06T22:03:20.281Z",
        "attributes": [
            {
                "trait_type": "Base",
                "value": "Starfish"
            },
            {
                "trait_type": "Eyes",
                "value": "Big"
            },
            {
                "display_type": "boost_number",
                "trait_type": "Generation",
                "value": "10",
                "max_value": "100"
            },
            {
                "display_type": "boost_number",
                "trait_type": "Eyes",
                "value": "15",
                "max_value": "100"
            }
        ],
        "_id": "62f95bb53dabd9f0cb740c10",
        "issuerId": "62f78c230af4b000190d6f4c",
        "ownerId": "62f78c230af4b000190d6f4c",
        "imageName": "1125jpg-1660504989006.jpg",
        "imageHash": "96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64",
        "thumbNail": "",
        "txHash": "0x",
        "category": "Alice NFT description",
        "subject": "Alice NFT",
        "place": "Montreal",
        "dateofIssue": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
        "productionYear": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
        "height": "50",
        "width": "10",
        "depth": "10",
        "unit": "Cm",
        "stockDetails": "",
        "issuerName": "aliceshop",
        "IpfsHash": "QmfAtXKmGzHdcB5TYYxVTG5ut34up3aE4iq3FJKgXoCSJM",
        "quantity": 1,
        "salesquantity": 1,
        "type": "Digital art",
        "createdDate": "2022-08-14T19:23:11.631Z",
        "__v": 0,
        "id": "62f94b9f3dabd9f0cb73fed6"
    },
    "metadataipfs": "QmRM5GMe72PAAkzotQREKC2F8jHAYYcYVkkDcC25Mpop77",
    "imageipfs": "QmfAtXKmGzHdcB5TYYxVTG5ut34up3aE4iq3FJKgXoCSJM"
}

After uploading the NFT, now she can mint it to the polygon blockchain. In order to mint it she needs to have the image id which we can found it in the previous response 62f95bb53dabd9f0cb740c10 or via calling /api/users/getFilesUnverified to get the list of uploaded files. Since Alice wants to mint a single image she is going to call /api/users/UploadFileIntoBlockchainwithSQS.

curl --location --request POST 'https://dev.chaincerts.org:3030/api/users/UploadFileIntoBlockchainwithSQS' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDg4MjAsImV4cCI6MTY2MDUxMjQyMH0.jHXvw-_W_XjMNzhttfN10yU57hoUYoHWk6lmuREUYuM' \
--header 'Content-Type: application/json' \
--header 'Cookie: connect.sid=s%3A25CQE9CKxok95I0yfP8PrTvSjbOJW4qJ.zs54%2BcYUlz%2BJYUelXPn%2FW1fH8hkLUIrKIc%2FbDQco%2FEw; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDMxMzYsImV4cCI6MTY2MDUwNjczNn0.ffzzpGCtH40Pk27PwJr69Kob_vZPXZnw4PosRHwZArg' \
--data-raw '{
    "userId": "62f78c230af4b000190d6f4c",
    "imageId": "62f95bb53dabd9f0cb740c10"
}'

The call was successful, the transaction for minting is now inserted to queue for processing, and she receives the following response.

{
    "status": true,
    "msg": "Successfully inserted in Queue for Processing",
    "data": {
        "imageId": "62f95bb53dabd9f0cb740c10"
    }
}

Alice now needs to wait a few minutes for the image to be minted. To verify the image status Alice calls /api/users/getFilesById.

curl --location --request POST 'https://dev.chaincerts.org:3030/api/users/getFilesById' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDg4MjAsImV4cCI6MTY2MDUxMjQyMH0.jHXvw-_W_XjMNzhttfN10yU57hoUYoHWk6lmuREUYuM' \
--header 'Content-Type: application/json' \
--header 'Cookie: connect.sid=s%3A25CQE9CKxok95I0yfP8PrTvSjbOJW4qJ.zs54%2BcYUlz%2BJYUelXPn%2FW1fH8hkLUIrKIc%2FbDQco%2FEw; token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MDMxMzYsImV4cCI6MTY2MDUwNjczNn0.ffzzpGCtH40Pk27PwJr69Kob_vZPXZnw4PosRHwZArg' \
--data-raw '{
    "imageId": "62f95bb53dabd9f0cb740c10"
}'

As we can see from the following response, the image status is now Verified which means it’s successfully minted to the blockchain.

{
    "status": true,
    "msg": "Successfull",
    "org_ownerId": "62f78c230af4b000190d6f4c",
    "data": {
        "validUntil": "2022-08-31",
        "linkedTo": "None",
        "isOwned": "Yes",
        "events": [
            {
                "type": "Creation",
                "Msg": "New certificate is created",
                "txHash": "0x2a5b92d178f9bdf762f1821186ff7c21f4e4ae36c6345901e8a960e1f1fc6fc0",
                "date": "2022-08-14T20:33:44.804Z",
                "chainId": "137",
                "contract_address": "0x964C2771B4792cEABf508f853751b35f20E5D8E5",
                "owner_address": "0x46a6a374CB2B6143521369990c7F7021c215ba62",
                "token_id": 173
            }
        ],
        "imageStatus": "Verified",
        "forSaleStatus": false,
        "price": 0,
        "validForSaleFrom": "2010-01-06T22:03:20.281Z",
        "validForSaleUntil": "2030-01-06T22:03:20.281Z",
        "attributes": [
            {
                "trait_type": "Base",
                "value": "Starfish"
            },
            {
                "trait_type": "Eyes",
                "value": "Big"
            },
            {
                "display_type": "boost_number",
                "trait_type": "Generation",
                "value": "10",
                "max_value": "100"
            },
            {
                "display_type": "boost_number",
                "trait_type": "Eyes",
                "value": "15",
                "max_value": "100"
            }
        ],
        "_id": "62f95bb53dabd9f0cb740c10",
        "issuerId": "62f78c230af4b000190d6f4c",
        "ownerId": "62f78c230af4b000190d6f4c",
        "imageName": "1125jpg-1660509108700.jpg",
        "imageHash": "96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64",
        "thumbNail": "",
        "txHash": "0x2a5b92d178f9bdf762f1821186ff7c21f4e4ae36c6345901e8a960e1f1fc6fc0",
        "category": "Alice NFT description",
        "subject": "Alice NFT",
        "place": "Montreal",
        "dateofIssue": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
        "productionYear": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
        "height": "50",
        "width": "10",
        "depth": "10",
        "unit": "Cm",
        "stockDetails": "",
        "issuerName": "aliceshop",
        "IpfsHash": "QmfAtXKmGzHdcB5TYYxVTG5ut34up3aE4iq3FJKgXoCSJM",
        "quantity": 1,
        "salesquantity": 1,
        "type": "Digital art",
        "createdDate": "2022-08-14T20:31:49.476Z",
        "__v": 0,
        "metaDataIpfsHash": "",
        "tokenId": 173,
        "id": "62f95bb53dabd9f0cb740c10"
    }
}

We can verify this transaction on polygon scan using transaction hash provided in the previous response https://polygonscan.com/tx/0x2a5b92d178f9bdf762f1821186ff7c21f4e4ae36c6345901e8a960e1f1fc6fc0.

10.png

Moreover, the NFT can be viewed on opensea. In the description section we found the description, properties and the boosts values specified when Alice uploaded the file.
11.png

Great ! So now Alice has successfully minted the NFT. In order to transfer the NFT to Bob, Bob must create an account on chaincerts. To do so, he needs to call /api/users/signup.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/signup' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'firstName=bob&lastName=bob&username=bob&email=bob%40gmail.co&userRole=client&password=bob%40123'

Bob account is successfully created, and he receives the following response:

{
  "status": true,
  "msg": "User has been registered successfully",
  "data": {
    "userRole": "client",
    "amount": 0,
    "userStatus": "active",
    "store_opening_date": "2010-01-06T22:03:20.281Z",
    "store_ending_date": "2030-01-06T22:03:20.281Z",
    "phoneNumberVerified": "false",
    "twoFacAuthEnabled": "false",
    "isShippingAddressUS": false,
    "_id": "62f967903dabd9f0cb741620",
    "firstName": "bob",
    "lastName": "bob",
    "username": "bob",
    "email": "bob@gmail.co",
    "verificationCode": 813501,
    "publicKey": "0x2e3Cd36ac34175CB4BAB19aA93E9a9Fe29EBef27",
    "createdDate": "2022-08-14T21:22:24.316Z",
    "__v": 0,
    "id": "62f967903dabd9f0cb741620"
  }
}

Bob will receive a verification code in his email in order to confirm it. The endpoint used to confirm the email is /api/users/confirm-verification-code.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/confirm-verification-code' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'userId=62f967903dabd9f0cb741620&code=813501'

Bob’s email is now verified, and he receives the following response.

{
  "status": true,
  "msg": "Your email has been verified!",
  "data": {
    "userRole": "client",
    "amount": 0,
    "userStatus": "active",
    "store_opening_date": "2010-01-06T22:03:20.281Z",
    "store_ending_date": "2030-01-06T22:03:20.281Z",
    "phoneNumberVerified": "false",
    "twoFacAuthEnabled": "false",
    "isShippingAddressUS": false,
    "_id": "62f967903dabd9f0cb741620",
    "firstName": "bob",
    "lastName": "bob",
    "username": "bob",
    "email": "bob@gmail.com",
   "publicKey": "0x2e3Cd36ac34175CB4BAB19aA93E9a9Fe29EBef27",
    "createdDate": "2022-08-14T21:22:24.316Z",
    "__v": 0,
    "id": "62f967903dabd9f0cb741620"
  }
}

Alice now can send the NFT using Bob id for the receiver id using /api/users/transferSinglewithsqs endpoint.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/transferSinglewithsqs' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA1MTI5ODksImV4cCI6MTY2MDUxNjU4OX0.KW3I4uNYWpyxM1SgAPxYTttg7m9z8zuV3LqJz4gnzao' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'userId=62f78c230af4b000190d6f4c&receiverId=62f967903dabd9f0cb741620&imageId=62f95bb53dabd9f0cb740c10&quantity=1&password=alice%40123'

The transfer was successful as shown in the following response and the transaction is inserted to the queue for processing.

{
  "status": true,
  "msg": "Successfully inserted in Queue for Processing",
  "data": {
    "imageId": "62f95bb53dabd9f0cb740c10"
  }
}

We can check that the image is successfully transferred by calling /api/users/getFilesById.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/getFilesById' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'imageId=62f95bb53dabd9f0cb740c10'

As we can see the quantity is now 0.

{
  "status": true,
  "msg": "Successfull",
  "org_ownerId": "62f78c230af4b000190d6f4c",
  "data": {
    "validUntil": "2022-08-31",
    "linkedTo": "None",
    "isOwned": "No",
    "events": [
      {
        "type": "Creation",
        "Msg": "New certificate is created",
        "txHash": "0x2a5b92d178f9bdf762f1821186ff7c21f4e4ae36c6345901e8a960e1f1fc6fc0",
        "date": "2022-08-14T20:33:44.804Z",
        "chainId": "137",
        "contract_address": "0x964C2771B4792cEABf508f853751b35f20E5D8E5",
        "owner_address": "0x46a6a374CB2B6143521369990c7F7021c215ba62",
        "token_id": 173
      },
      {
        "type": "Transferred",
        "Msg": "Certificate is Transferred.",
        "txHash": "0x7192469306cab93b6137c00b7731acebb06c1d8309408bf4f73e23d10682936f",
        "date": "2022-08-15T16:42:36.632Z"
      }
    ],
    "imageStatus": "Verified",
    "forSaleStatus": false,
    "price": 0,
    "validForSaleFrom": "2010-01-06T22:03:20.281Z",
    "validForSaleUntil": "2030-01-06T22:03:20.281Z",
    "attributes": [
      {
        "trait_type": "Base",
        "value": "Starfish"
      },
      {
        "trait_type": "Eyes",
        "value": "Big"
      },
      {
        "display_type": "boost_number",
        "trait_type": "Generation",
        "value": "10",
        "max_value": "100"
      },
      {
        "display_type": "boost_number",
        "trait_type": "Eyes",
        "value": "15",
        "max_value": "100"
      }
    ],
    "_id": "62f95bb53dabd9f0cb740c10",
    "issuerId": "62f78c230af4b000190d6f4c",
    "ownerId": "62f78c230af4b000190d6f4c",
    "imageName": "1125jpg-1660509108700.jpg",
    "imageHash": "96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64",
    "thumbNail": "",
    "txHash": "0x2a5b92d178f9bdf762f1821186ff7c21f4e4ae36c6345901e8a960e1f1fc6fc0",
    "category": "Alice NFT description",
    "subject": "Alice NFT",
    "place": "Montreal",
    "dateofIssue": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
    "productionYear": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
    "height": "50",
    "width": "10",
    "depth": "10",
    "unit": "Cm",
    "stockDetails": "",
    "issuerName": "aliceshop",
    "IpfsHash": "QmfAtXKmGzHdcB5TYYxVTG5ut34up3aE4iq3FJKgXoCSJM",
    "quantity": 0,
    "salesquantity": 0,
    "type": "Digital art",
    "createdDate": "2022-08-14T20:31:49.476Z",
    "__v": 1,
    "metaDataIpfsHash": "",
    "tokenId": -1,
    "id": "62f95bb53dabd9f0cb740c10"
  }
}

After transferring, a new image is created automatically owned by Bob. In order to get the new file id Bob called /api/users/imageSecondTransferdropshop and provided the old image id.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/imageSecondTransferdropshop' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY5Njc5MDNkYWJkOWYwY2I3NDE2MjAiLCJpYXQiOjE2NjA1ODc3NzAsImV4cCI6MTY2MDU5MTM3MH0.4ZHF7tjF5UwDZCEhAjaA_z_rkstGewbs4OcmXyi2hN8' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'imageId=62f95bb53dabd9f0cb740c10'

The NFT is transferred to the public key of Bob created at signup. Bob can get his public key using this api /api/users/getUserById

curl -X 'GET' \
  'https://dev.chaincerts.org:3030/api/users/getUserById?userId=62f967903dabd9f0cb741620' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY5Njc5MDNkYWJkOWYwY2I3NDE2MjAiLCJpYXQiOjE2NjA1ODI1OTksImV4cCI6MTY2MDU4NjE5OX0.zAP8a5FeDjJpt91jKV4ac73SRKRfxLi7I3_FM3bIXU8'

In the response we can see the new image id.

{
  "status": true,
  "imageId": "62fa777c0af4b0001910135f",
  "ownerId": "62f967903dabd9f0cb741620"
}

The public key can be found in the publicKey field. Bob public key is 0x2e3Cd36ac34175CB4BAB19aA93E9a9Fe29EBef27

{
  "status": true,
  "msg": "Get user data successfully",
  "data": {
    "userRole": "client",
    "amount": 0,
    "userStatus": "active",
    "store_opening_date": "2010-01-06T22:03:20.281Z",
    "store_ending_date": "2030-01-06T22:03:20.281Z",
    "phoneNumberVerified": "false",
    "twoFacAuthEnabled": "false",
    "isShippingAddressUS": false,
    "_id": "62f967903dabd9f0cb741620",
    "firstName": "bob",
    "lastName": "bob",
    "username": "bob",
    "email": "bob@gmail.co",
    "verificationCode": 813501,
    "publicKey": "0x2e3Cd36ac34175CB4BAB19aA93E9a9Fe29EBef27",
    "createdDate": "2022-08-14T21:22:24.316Z",
    "__v": 0,
    "emailVerifiedAt": "2022-08-14T21:29:11.199Z",
    "id": "62f967903dabd9f0cb741620"
  }
}

We can also check the new owner of the NFT on opensea.
12.png

Collector workflow

Step 1: signup

The first step is to sign up using the /api/users/singup. At signup a new user is created with the provided first name, last name, username, email, role and password. In case of email or username duplication an error will be raised. The associated role for NFT creator is client. Once a user is created a key pair will be generated. The private key can be retrieved using /api/users/getuserPrivateKeybyPwd.

Step 2: Send verification code

Send verification code via email to confirm user email using /api/users/send-verification-code endpoint. User Id is required.

Step 3: Confirm email

Confirm email by sending the code received by email and the user id to /api/users/ConfirmVerificationCode endpoint. User Id is required.

Step 4: Login

In order to use most of the rest APIs, authentication is required via /api/users/login endpoint by providing the user email and password. If login is successful a bearer token will be sent in the response that must be sent in the Authorization parameter. The word Bearer must be added before the token.

Step 6: Get the list of NFTs for sales

There is three endpoints to list NFTs for sales, the first one is /api/users/getForSaleCertificateByUsername to get the NFTs for sales owned by the user with the provided username. The second one /api/users/sortForSaleCertificates to get the NFTs for sales owned by the user with the provided username ordered by the provided price order (ascending or descending). The third one is /api/users/filterForSaleCertificates to get the NFTs for sales owned by the user with the provided username where the type equals the provided type. All the endpoints support pagination by specifying the page number using page query parameter and number of files to return using pagination query parameter. If the pagination parameters are not defined the API will return the first eight files.

Step 7: Buy NFT

There are three ways to buy NFT from chaincerts, using credit card, using cryptocurrency with the public key generated at signup or with cryptocurrency using metamask wallet.

a - Using credit card

b - Using cryptocurrency default public key

c - Cryptocurrency metamask

Step 8: Get bought collection

To get the list of owned NFTs use /api/users/getFilesByuserId endpoint and provide your user id. /api/users/searchingFiles endpoint can be used to list files owned by the user with the provided user ID / username and where the subject of the file contains the word provided as search parameter.

Example Buy NFT using credit card

Alice wants to put an NFT for sale on the chaincerts marketplace. And Bob is looking for amazing NFTs to buy.

Alice first will repeat the previous steps which are upload NFT and then mint the NFT to the blockchain. The image id is 62fb82140a3678bba49f43a0.

To put the NFT for sale alice call /api/users/changeForSaleStauts endpoint and specify the price of the NFT.

curl -X 'POST' \
  'https://dev.chaincerts.org:3030/api/users/changeForSaleStatus?userId=62f78c230af4b000190d6f4c' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA2NDk5ODQsImV4cCI6MTY2MDY1MzU4NH0.B7ZekHp2G5JEqTyw1dSXB-31nJiW_NsZ8fY0XJ9q9o8' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'imageId=62fb82140a3678bba49f43a0&forSaleStatus=true&price=1000'

The NFT is successfully put for sale and Alice receives the following response.

{
  "status": true,
  "msg": "image data updated Successfully",
  "data": {
    "validUntil": "2022-08-31",
    "linkedTo": "None",
    "isOwned": "Yes",
    "events": [
      {
        "type": "Creation",
        "Msg": "New certificate is created",
        "txHash": "0x44105c16292241b99df7dd064e22997529e60bd95f31416758e91606cd456fe2",
        "date": "2022-08-16T11:41:28.482Z",
        "chainId": "137",
        "contract_address": "0x2539ce25b45ba38e48f29171844ceb0e2f07c989",
        "owner_address": "0x46a6a374CB2B6143521369990c7F7021c215ba62",
        "token_id": 73
      }
    ],
    "imageStatus": "Verified",
    "forSaleStatus": true,
    "price": 1000,
    "validForSaleFrom": "2010-01-06T22:03:20.281Z",
    "validForSaleUntil": "2030-01-06T22:03:20.281Z",
    "attributes": [
      {
        "trait_type": "Base",
        "value": "Starfish"
      },
      {
        "trait_type": "Eyes",
        "value": "Big"
      },
      {
        "display_type": "boost_number",
        "trait_type": "Generation",
        "value": "10",
        "max_value": "100"
      },
      {
        "display_type": "boost_number",
        "trait_type": "Eyes",
        "value": "15",
        "max_value": "100"
      }
    ],
    "_id": "62fb82140a3678bba49f43a0",
    "issuerId": "62f78c230af4b000190d6f4c",
    "ownerId": "62f78c230af4b000190d6f4c",
    "imageName": "monkeyg412399084_1280jpg-1660650003269.jpg",
    "imageHash": "96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64",
    "thumbNail": "",
    "txHash": "0x44105c16292241b99df7dd064e22997529e60bd95f31416758e91606cd456fe2",
    "category": "Alice NFT description",
    "subject": "Alice NFT 2",
    "place": "Montreal",
    "dateofIssue": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
    "productionYear": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
    "height": "50",
    "width": "10",
    "depth": "10",
    "unit": "Cm",
    "stockDetails": "",
    "issuerName": "aliceshop",
    "IpfsHash": "QmTg1wFYihfnJJrgHA9ZHdViRKhDruX84ScTHrebFeteFi",
    "quantity": 1,
    "salesquantity": 1,
    "type": "Digital art",
    "createdDate": "2022-08-16T11:40:04.778Z",
    "__v": 0,
    "metaDataIpfsHash": "",
    "tokenId": 73,
    "id": "62fb82140a3678bba49f43a0"
  }
}

The NFT can be found on opensea.

15.png

Bob wants to buy a NFT from alice shop. He calls /api/users/getForSaleCertificateByUsername to get the NFTs for sales owned by Alice.

curl -X 'GET' \
  'https://dev.chaincerts.org:3030/api/users/getForSaleCertificatesByUsername?username=aliceshop' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MmY3OGMyMzBhZjRiMDAwMTkwZDZmNGMiLCJpYXQiOjE2NjA2NDk5ODQsImV4cCI6MTY2MDY1MzU4NH0.B7ZekHp2G5JEqTyw1dSXB-31nJiW_NsZ8fY0XJ9q9o8'

He receives the list of NFTs for sale in the response. In our case only one NFT is for sale.

{
  "status": true,
  "msg": "These certificates were found for this username",
  "data": [
    {
      "validUntil": "2022-08-31",
      "linkedTo": "None",
      "isOwned": "Yes",
      "events": [
        {
          "type": "Creation",
          "Msg": "New certificate is created",
          "txHash": "0x44105c16292241b99df7dd064e22997529e60bd95f31416758e91606cd456fe2",
          "date": "2022-08-16T11:41:28.482Z",
          "chainId": "137",
          "contract_address": "0x2539ce25b45ba38e48f29171844ceb0e2f07c989",
          "owner_address": "0x46a6a374CB2B6143521369990c7F7021c215ba62",
          "token_id": 73
        }
      ],
      "imageStatus": "Verified",
      "forSaleStatus": true,
      "price": 1000,
      "validForSaleFrom": "2010-01-06T22:03:20.281Z",
      "validForSaleUntil": "2030-01-06T22:03:20.281Z",
      "attributes": [
        {
          "trait_type": "Base",
          "value": "Starfish"
        },
        {
          "trait_type": "Eyes",
          "value": "Big"
        },
        {
          "display_type": "boost_number",
          "trait_type": "Generation",
          "value": "10",
          "max_value": "100"
        },
        {
          "display_type": "boost_number",
          "trait_type": "Eyes",
          "value": "15",
          "max_value": "100"
        }
      ],
      "_id": "62fb82140a3678bba49f43a0",
      "issuerId": "62f78c230af4b000190d6f4c",
      "ownerId": "62f78c230af4b000190d6f4c",
      "imageName": "monkeyg412399084_1280jpg-1660650003269.jpg",
      "imageHash": "96381f47203ead02dd11162bf74b09f5d44b9136149d42001e6475757e9cbe64",
      "thumbNail": "",
      "txHash": "0x44105c16292241b99df7dd064e22997529e60bd95f31416758e91606cd456fe2",
      "category": "Alice NFT description",
      "subject": "Alice NFT 2",
      "place": "Montreal",
      "dateofIssue": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
      "productionYear": "Sun Aug 14 2022 00:00:00 GMT 0100 (Central European Standard Time)",
      "height": "50",
      "width": "10",
      "depth": "10",
      "unit": "Cm",
      "stockDetails": "",
      "issuerName": "aliceshop",
      "IpfsHash": "QmTg1wFYihfnJJrgHA9ZHdViRKhDruX84ScTHrebFeteFi",
      "quantity": 1,
      "salesquantity": 1,
      "type": "Digital art",
      "createdDate": "2022-08-16T11:40:04.778Z",
      "__v": 0,
      "metaDataIpfsHash": "",
      "tokenId": 73,
      "id": "62fb82140a3678bba49f43a0"
    }
  ],
  "totalCert": 1
}

Conclusion

Using chaincerts endpoints allows you to build an NFT marketplace in an easy and secure way, with the freedom to use any frontend platform of your choice.