Web3 API

This page shows you how to integrate Merso using Web3. This means that your players with pay the NFT using tokens or cryptocurrencies.

🎯 Integration Overview

The Merso API provides three core endpoints for game integration:

  • /health - API health check

  • /merso-user-approval - Approve ERC20 token spending

  • /merso-buy-token - Purchase NFT using Merso System

📋 Web3 API Endpoints

1. Health Check

Endpoint: GET /health

Purpose: Verify API connectivity and status

Request:

curl -X GET "https://api3.dev.merso.io/health"

Response:

{
  "success": true,
  "message": "Merso Backend is running",
}

JavaScript Example:

2. User Approval

Endpoint: POST /merso-user-approval

Purpose: Approve Merso System to spend user's ERC20 tokens. You can choose between PNPL or Upfront approve. New optional params added.

Request :

Parameters:

  • userAddress (string): User's wallet address.

  • userEmail (string): User's in-game email.

  • tokenPrice (string): Amount to approve (in wei).

  • collectionAddress (string): NFT collection contract address.

Optionals:

  • paymentMode (string): Desired way to pay the asset. Values must be: "BNPL" or "UPFRONT". Default in case you don't want/need it to send is set as "BNPL"

  • chainId (int): EVM chain ID used to process the payment. If not provided, the protocol will use the default chain configured during the game’s registration process.

  • tokenAddress (string): ERC-20 token contract address used for the payment. If not provided, the protocol will use the default payment token configured during the game’s registration process.

Response:

JavaScript Example:

3. Buy Token with Merso

Endpoint: POST /merso-buy-token

Purpose: Purchase NFT using Merso functionality. You can choose between PNPL or Upfront payment. New optional params added.

Request:

Parameters:

  • userAddress (string): User's wallet address.

  • tokenId (string): NFT token ID to purchase.

  • tokenPrice (string): Total price in wei.

  • collectionAddress (string): NFT collection contract address.

Optionals:

  • paymentMode (string): Desired way to pay the asset. Values must be: "BNPL" or "UPFRONT". Default in case you don't want/need it to send is set as "BNPL"

  • chainId (int): EVM chain ID used to process the payment. If not provided, the protocol will use the default chain configured during the game’s registration process.

  • tokenAddress (string): ERC-20 token contract address used for the payment. If not provided, the protocol will use the default payment token configured during the game’s registration process.

Response:

JavaScript Example:

🔄 Integration Flow

Complete Purchase Flow

Last updated