Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/WilfredAlmeida/capi
Solana cNFT API as a Service
https://github.com/WilfredAlmeida/capi
Last synced: about 1 month ago
JSON representation
Solana cNFT API as a Service
- Host: GitHub
- URL: https://github.com/WilfredAlmeida/capi
- Owner: WilfredAlmeida
- License: apache-2.0
- Created: 2023-08-02T06:17:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-11T00:44:26.000Z (11 months ago)
- Last Synced: 2024-08-01T08:11:09.275Z (4 months ago)
- Language: TypeScript
- Homepage:
- Size: 352 KB
- Stars: 16
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - WilfredAlmeida/capi - Solana cNFT API as a Service (TypeScript)
README
![CAPI](https://github.com/WilfredAlmeida/capi/assets/60785452/4bcf7fac-04a0-4307-b6c0-ae79a7beaacf)
# 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
List Collection Items
## 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 |
| | | |2. `/auth/key/new`: Creates a new API key for CAPI
Type: POST
Body: None
Returns:
| | | |
| --- | --- | --- |
| key | string | CAPI API Key |
| | | |3. `/nft/mint`: Mint NFT Collection
Type: POST
Header: Authorization `Bearer `
Body:
Example
```json
{
"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 ImageReturns:
- `signatures`: string[]: Mint transactions
- `collectionMint`: string: Collection Mint4. `/nft/list/:collectionMint?page=1&pageSize=10`: Get a list of all NFTs minted in a collection
Type: GET
Header: Authorization `Bearer `
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](https://unkey.dev) admin key
- `UNKEY_API_ID`: Unkey API id## Database Schema
![dbDiagram](https://github.com/WilfredAlmeida/capi/assets/60785452/d756f03b-ed66-4585-b22a-b78c5a594faf)Here's the SQL for creating tables:
Supabase Postgres
```sql
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.