Skip to content

WilfredAlmeida/capi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CAPI

CAPI: cNFT API as a Service

CAPI is a Compressed NFT (cNFT) API as a service that provides APIs to mint compressed NFTs (cNFT).

CAPI takes in your collection details and NFT details and mints them to the provided addresses. You don't have to worry about the complexities of Merkle trees, Gas, or the chain in any sense. All you have to do is call the CAPI API.

CAPI stores your images, creates metadata for collection and images, stores the metadata JSON files, creates merkle tree and collection and mints the cNFTs.

CAPI uses the Helius DAS API to provide you with fast access to your minted cNFTs. Additionally, CAPI stores data about your mints to provide you with tracking and other desired usability features.

Demo

Mint Collection
capi-demo-compressed.mp4
List Collection Items
list-demo.mp4

Api Reference

  1. /user/create: Creates a new CAPI user in DB. Call this after authentication

Type: POST

Body:

email string User email

Returns:

userId int User Id
  1. /auth/key/new: Creates a new API key for CAPI

Type: POST

Body: None

Returns:

key string CAPI API Key
  1. /nft/mint: Mint NFT Collection

Type: POST

Header: Authorization Bearer <API KEY>

Body:
Example

{
    "collection": {
        "nftCount": 10,
        "mintAllTo": "someDaddyAddress",
        "collectionName": "Never gonna let you go",
        "collectionSymbol": "CAPI",
        "collectionImage": "ImageBase64"
    },
    "nft": [
        {
            "name": "Rickroll",
            "symbol": "Drums",
            "description": "Minted via Capi",
            "receiver": null,
            "image": "ImageBase64"
        },
        {
            "name": "Ping Pong",
            "symbol": "SomeSymbol",
            "description": "Your Hackathon Prize",
            "receiver": "SomeAddress",
            "image": "ImageBase64"
        }
    ]
}

Params Explained:
All params are required

collection:

  • nftCount: int: Count of total cNFTs to mint
  • mintAllTo: Default address to mint all cNFTs to
  • collectionName: Collection Name
  • collectionSymbol: Collection Symbol
  • collectionImage: Collection image in base64 encoding

nft: List of:

  • name: cNFT Name
  • Symbol: cNFT Symbol
  • description: Description of cNFT
  • receiver: Receiver Address. nullable
  • image: cNFT Image

Returns:

  • signatures: string[]: Mint transactions
  • collectionMint: string: Collection Mint
  1. /nft/list/:collectionMint?page=1&pageSize=10: Get a list of all NFTs minted in a collection

Type: GET

Header: Authorization Bearer <API KEY>

Params:

  • collectionMint: The collection mint returned after minting
  • page: Page index for paginated response
  • pageSize: Page size

Env Config

  • PORT: Server Port
  • SUPABASE_URL: Supabase URL
  • SUPABASE_ANON_KEY: Supabase Anon Key
  • NODE_ENV: Node evn, Eg. production, staging, development
  • HELIUS_KEY: Helius API Key
  • UNKEY_KEY: Unkey admin key
  • UNKEY_API_ID: Unkey API id

Database Schema

dbDiagram

Here's the SQL for creating tables:

Supabase Postgres
CREATE TABLE "users" (
"user_id" varchar(26) PRIMARY KEY NOT NULL,
"email" varchar UNIQUE NOT NULL,
"key_id" text,
"user_status" integer DEFAULT 0
);

CREATE TABLE "collection" (
"collection_id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY NOT NULL,
"user_id" varchar(26) NOT NULL,
"name" text NOT NULL,
"symbol" text NOT NULL,
"image_url" text NOT NULL,
"uri_url" text NOT NULL,
"mint" text,
"token_account" text,
"metadata_account" text,
"master_edition_account" text,
"seller_fee_basis_points" integer DEFAULT 100,
"creators" creator_info[],
"collection" text,
"uses" text,
"mutable" bool DEFAULT true,
"collection_details" text
);

CREATE TABLE "tree" (
"tree_id" integer PRIMARY KEY NOT NULL,
"collection_id" integer NOT NULL,
"max_depth" integer DEFAULT 3,
"canopy_depth" integer DEFAULT 3,
"payer" text NOT NULL,
"storage_cost" integer,
"keypair" integer
);

CREATE TABLE "keypair" (
"keypair_id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY NOT NULL,
"public_key" text NOT NULL,
"secret_key" text NOT NULL,
"keypair_type" integer NOT NULL DEFAULT 0
);

CREATE TABLE "mints" (
"mint_id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"user_id" varchar(26),
"collection_id" integer NOT NULL,
"transaction_signatures" text[]
);

COMMENT ON COLUMN "users"."user_id" IS 'A valid ULID';

COMMENT ON COLUMN "users"."user_status" IS 'status of user. Valid status values are:
1. created,
2. active,
3. upgraded,
4. inactive,
5. blocked,
6. services disabled (eg. free tier expired),
7. pending actions (eg. not paid fees)';

ALTER TABLE "collection" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("user_id");

ALTER TABLE "tree" ADD FOREIGN KEY ("collection_id") REFERENCES "collection" ("collection_id");

ALTER TABLE "tree" ADD FOREIGN KEY ("keypair") REFERENCES "keypair" ("keypair_id");

ALTER TABLE "mints" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("user_id");

ALTER TABLE "mints" ADD FOREIGN KEY ("collection_id") REFERENCES "collection" ("collection_id");

Tech Used

  • Express-TypeScript
  • Supabase DB & Storage
  • Bubblegum Protocol
  • Metaplex SDK
  • Helius DAS API

FAQ

  1. Where are metadata files stored?
    Metadata JSON and image files are stored in Supabase storage and their public URLs are used while minting.

  2. Why is Supabase DB used?
    Metadata like collection info, tree info, mint into, transaction signatures and, more are stored in the relational database. See the schema in the next section.

  3. What is the use of Unkey?
    Unkey is an open-source API key management platform used to provision and manage CAPI API keys with features like on-the-edge rate limiting and more.

  4. How are cNFTs minted? cNFTs are minted using the Bubblegum protocol by Metaplex Foundation.

  5. Who pays for the gas for minting?
    cAPI as a service takes care of the gas and other costs. This enables sponsored/funded minting of cNFTs.

  6. What is the use of Helius?
    Helius' DAS API is used to fetch cNFT information. The service is fast and efficient.

About

Solana cNFT API as a Service

Resources

License

Stars

Watchers

Forks