Code Monkey home page Code Monkey logo

minting-api-backend's Introduction

Minting API Backend for conducting a free mint

This project is a backend API for doing a free mint on IMX zkEVM.

Disclaimer

The sample code provided is for reference purposes only and is not officially supported by Immutable. It has undergone best effort testing by Immutable to ensure basic functionality. However, it is essential that you thoroughly test this sample code within your own environment to confirm its functionality and reliability before deploying it in a production setting. Immutable disclaims any liability for any issues that arise due to the use of this sample code. By using this sample code, you agree to perform due diligence in testing and verifying its suitability for your applications.

Features

  • Uses the Immutable Minting API to ensure that minting is sponsored & transaction life cycle monitoring, nonce management etc. is abstracted.
  • Accounts for race conditions by locking the DB during minting for a specific address.
  • Records all tokens minted in a DB, both during pending & succeeded states. If the server crashes or a large amount of mints are pending, it's counted in the max supply.
  • Ability to allowlist addresses for minting and designate a quantity. For example, an address has the right to mint 5 tokens.
  • Webhook support for minting events, no need for polling. Also allows for asynchronous updating from a pending to succeeded or failed state.
  • Authenticated requests that are verified from both Passport and from IMX for webhooks, both on subscription & notifications.
  • Rich logging using Winston for troubleshooting & debugging.
  • Define phases that the mint should occur in, with different max supplies, start times, end times, and whether the phase is allowlisted.

Setup Instructions

  1. Install the dependencies:

    npm i
    
  2. Copy the example environment file and fill it with your API key, and DB path(should be file:./allowList.db):

    cp .env.example .env
    
  3. Make sure to configure src/config.ts with your collection address after deploying the contract on hub.immutable.com. Pay specific attention to the mintPhases parameter:

    mintPhases: [
      {
        name: "Presale",
        startTime: 1629913600,
        endTime: 1629999999,
        enableAllowList: true,
      },
      {
        name: "Public Sale",
        startTime: 1630000000,
        endTime: 1719292800,
        enableAllowList: false,
      }],
    

    Keep in mind that you can configure a single phase if you're not planning a phased approach but just a start/end time.

  4. Populate your metadata in server.ts by following this format.

  5. Run the DB migrations:

    npx prisma migrate dev
    
  6. Load your database, https://sqlitebrowser.org/ is great for this. You can also write a script that uses the Prisma client to load the database. Make sure you have your address allowlisted, and quantity is 1, isLocked is 0, hasMinted is 0.

  7. Run the development server:

    npm start
    
  8. Create your webhook at https://hub.immutable.com/, use localtunnel for testing webhooks locally:

    npx localtunnel --port 3000
    

    Use the above URL for the webhook endpoint with the path /webhook. For example: https://ten-rooms-vanish.loca.lt/webhook.

To-Do List

  • Consider switching to Pino instead of Winston for logging
  • Troubleshoot why all console.log are not showing up in the console with logger.info
  • Add color coding to success or failure in the logs
  • Generally type more things like the mint requests etc.
  • Add ERC1155 support once the minting API is ready
  • Add the ability to choose whether you want mintByQuantity or mintByID

Tech Stack

  • Prisma ORM
  • sqlite3

minting-api-backend's People

Contributors

danekshea avatar zacharycouchman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.