Skip to content

Commit

Permalink
feat: add docker compose file for minting backend pg (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
shineli1984 authored Jun 6, 2024
1 parent 63e8e5a commit 1d9cdf2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 30 deletions.
10 changes: 10 additions & 0 deletions samples/minting-backend-with-postgres/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ERC721 or ERC1155 contract address
COLLECTION_ADDRESS=
# immutable secret API from hub.immutable.com
IM_API_KEY=

## DB
PG_USER=postgres
PG_PASSWORD=password
PG_HOST=postgres
DB_NAME=minting_backend
4 changes: 3 additions & 1 deletion samples/minting-backend-with-postgres/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ package-lock.json

# generated code
examples/typescript-server.js
test/types/index.js
test/types/index.js

!.env
22 changes: 15 additions & 7 deletions samples/minting-backend-with-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ This sample app uses Immutable minting backend SDK to manage minting. This repo

## Get Started

### pre-requisites
- NodeJS >= v20
- Docker
- You have ERC721 or ERC1155 deployed
- You have enabled [minting api](https://docs.immutable.com/docs/zkEVM/products/minting/minting-api#minting-api-prerequisites) for your contract.

### Install dependency

```bash
npm i # with nodejs version >= 20
npm i
```

### expose local port for webhook
Expand All @@ -19,20 +25,22 @@ You can use services like below to expose ports locally.

Please make sure the url with port 3000 exposed is set up in the webhook section in [Immutable Hub](hub.immmutable.com).

### run server
### Set environment variables
Set `COLLECTION_ADDRESS` and `IM_API_KEY` in the `./.env` file.

### Run the app

```bash
# Replace the contract address and api key from hub in the command below
COLLECTION_ADDRESS={your_nft_contract_address} IM_API_KEY={your_api_key} npm run dev
docker compose up --build
```

This will start a fastify server at port 3000.
This will start a fastify server at port 3000 and postgres container.

Make sure to trigger the confirmation event again on webhook page via hub if you have missed it the first time.

### mint
### Mint

Replace YOUR_WALLET_ADDRESS with your NFT recipient's wallet address. You can get a random eth address from [here](https://vanity-eth.tk/).
Replace `YOUR_WALLET_ADDRESS` with your NFT recipient's wallet address in the below command. You can get a random eth address from [here](https://vanity-eth.tk/).

```
curl -X POST -H "Content-Type: application/json" -d '{"mintTo": "YOUR_WALLET_ADDRESS"}' http://localhost:3000/mint
Expand Down
26 changes: 26 additions & 0 deletions samples/minting-backend-with-postgres/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.9'
services:
postgres:
image: postgres:14
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=minting_backend
expose:
- '5432'
ports:
- 5432:5432
volumes:
- ../../packages/minting-backend/sdk/src/persistence/pg/seed.sql:/docker-entrypoint-initdb.d/seed.sql
backend:
image: node:20-alpine
restart: always
ports:
- 3000:3000
depends_on:
- postgres
volumes:
- ./:/app
working_dir: /app
command: npm run dev
3 changes: 2 additions & 1 deletion samples/minting-backend-with-postgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Fastify, { FastifyReply, FastifyRequest } from 'fastify'
import { mintingBackend, config } from '@imtbl/sdk';
import { Pool } from 'pg';
import { v4 as uuidv4, parse } from 'uuid';
import 'dotenv/config'

const fastify = Fastify({
logger: true
Expand Down Expand Up @@ -67,7 +68,7 @@ fastify.post(url, async (request: FastifyRequest<any>, reply: any) => {
*/
const start = async () => {
try {
await fastify.listen({ port: 3000 })
await fastify.listen({ port: 3000, host: "0.0.0.0" })

// long running process to submit minting requests
await minting.submitMintingRequests({});
Expand Down
1 change: 1 addition & 0 deletions samples/minting-backend-with-postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@imtbl/sdk": "alpha",
"@types/pg": "^8.11.6",
"@types/uuid": "^9.0.8",
"dotenv": "^16.4.5",
"fastify": "^4.27.0",
"pg": "^8.11.5",
"uuid": "^9.0.1"
Expand Down
21 changes: 0 additions & 21 deletions samples/minting-backend-with-postgres/seed.sql

This file was deleted.

0 comments on commit 1d9cdf2

Please sign in to comment.