# Backend service for nftrade clone
## Collections
whenever user creates a collection successfully, metadata will be passed to backend via calling POST endpoint
format of payload:
`POST /api/v1/collections`
```json=
{
"address": "0x31385d3520bced94f77aae104b406994d8f2168c",
"metadata": {
"name": "OpenSea Creatures",
"symbol": "OSC",
"description": "OpenSea Creatures are adorable aquatic beings primarily for demonstrating what can be done using the OpenSea platform. Adopt one today to try out all the OpenSea buying, selling, and bidding feature set.",
"image": "https://openseacreatures.io/image.png",
"external_link": "https://openseacreatures.io"
},
"chainId": "137",
"type": "EIP721",
"preview": "added_by_backed",
"createdAt": "added_by_backend",
"updatedAt": "added_by_backend"
}
```
- `address` is unique identifier.
- `metadata` can have blank fields or empty properties
- `type` can be `EIP721` or `EIP1155`.
- `chainId` is number.
Before saving to DB, backend will add following keys:
- `preview`: url of scaled down version of `metadata.image` (upto 200px x & y) served via CDN for showing preview on frontend.
- `createdAt`: timestamp
- `updatedAt`: timestamp
then it will be saved to DB.
while querying via `GET /api/v1/collection`, would be able retrive via `address`, `chainId` and `type`
for example:
`GET /api/v1/collection?address="0x31385d3520bced94f77aae104b406994d8f2168c"`
`GET /api/v1/collection?chainId=137&limit=10&start=150&sort=asc`
(sort can be removed if complex, then it should be sorted descending by default)
limit = no. of objects in returned array
start = if start = 150 & limit = 10, returned array will have objects 150 to 160 (for pagination purposes)
`GET /api/v1/collection?search="some string"`
it will try to regex match `metadata.name`, `metadata.symbol` & `metadata.description`
here is example (https://api.nftrade.com/api/v1/contracts?limit=100&skip=0&verified=true&search=) we use term 'collection' instead of 'contracts' everywhere
## Tokens
A collection can have multiple tokens (represented by tokenId) but given token can only belong to single collection.
Users can create tokens(NFT) after they have created collection (as mentioned above), frontend will send post request to backend whenever new token is created.
format of payload:
`POST /api/v1/tokens`
```json=
{
"tokenId": "1",
"address": "0x31385d3520bced94f77aae104b406994d8f2168c",
"metadata": {
"name": "Dave Starbelly",
"description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
"external_url": "https://openseacreatures.io/3",
"image": "https://storage.googleapis.com/opensea-prod.appspot.com/puffs/3.png",
"attributes": [
{
"trait_type": "Base",
"value": "Starfish"
}
]
},
"price": "3.99",
"last_sell": "2.5",
"last_sell_at": "timestamp",
"highest_offer": "3.5",
"preview": "added_by_backend",
"orders": [
{
"id": "c9fbca6f-5124-4372-9aa4-6a121c4ce899",
"type": "SELL",
"state": "CANCELLED",
"format": {
"makerAddress": "0x544e3f54cad02f469e4038c235a459f62c9a06aa",
"feeRecipientAddress": "0x0000000000000000000000000000000000000000",
"makerAssetAmount": "1",
"takerAssetAmount": "500000000000000000000000000",
"makerAssetData": "0xSomeABIEncodedValue".
"takerSignature": "0xSomeValue",
"makerSignature": "0XSomeOtherValue"
}
}
]
}
```
- `tokenId` is unique per collection
- `address` identifies collection it belongs to
- `metadata` can have blank fields or empty properties
- `price`, `last_sell`, `last_sell_at` and `highest_offer` null at time creation (not supplied along with request) and can be updated later
- `preview`: url of scaled down version of `metadata.image` (upto 200px x & y) served via CDN for showing preview on frontend.
- `createdAt`: timestamp
- `updatedAt`: timestamp
- `orders[x].id` : unique Id to represent order
- `orders[x].type`: can be `SELL`, `LISTED`, `LIST_CANCELLED`
- `orders[x].status`: can be `CANCELLED`, `ADDED`
- `orders[x].format`: `0x` protocol order format requried fields
At the time of creation `orders` will be empty array
there will endpoint to add new items to `orders` which will be called via frontend.
once new item is added to `orders` then `price`, `last_sell`, `last_sell_at` `highest_offer` will be re-evaluated.
`GET` endpoints to retrive data and filter by paramters.
here is example from nftrade: https://api.nftrade.com/api/v1/tokens/0xf70576a5255fccfe6551f3ec8de74c9e002e1a82/3576?chainId=43114
(ours is more simplified)