Smart Contract Integration

This guide is for developers who want to integrate MakaPay at the smart contract level. Learn how to receive on-chain callbacks when payments are processed, enabling fully automated and trustless payment flows.


Overview

MakaPay V4 smart contracts provide:

  1. CREATE2 Deterministic Addresses: Payment addresses are computed before deployment

  2. On-Chain Callbacks: Your contract can receive notifications when payments arrive

  3. Frontrun Protection: Fee amounts are baked into the address computation

  4. Cross-Chain Recovery: Same address works on all EVM chains

┌─────────────────────────────────────────────────────────────────┐
│                     Payment Flow (V4)                           │
│                                                                 │
│  1. Compute Address ──→ 2. Customer Pays ──→ 3. Process Payment │
│                                                     │           │
│                                                     ▼           │
│                                           4. Callback to Your   │
│                                              Contract (optional)│
└─────────────────────────────────────────────────────────────────┘

The onPaymentReceived Callback

The most powerful feature for developers is the optional callback that V4 contracts can trigger when a payment is processed. If your merchant address is a smart contract that implements the callback interface, it will be called automatically.

Interface

When Is It Called?

The callback is triggered when all of these conditions are met:

  1. The payment is processed via PaymentWalletFactoryV4.process() or processNoFee()

  2. The merchant address has contract code (is a smart contract)

  3. The callbackData parameter is non-empty

Callback Data

The callbackData is arbitrary bytes that you define when creating the payment. This allows you to pass context to your contract, such as:

  • Order IDs

  • User identifiers

  • Product SKUs

  • Subscription IDs

  • Any custom data your application needs


Real-World Example: Gas Tank Deposits

MakaPay uses its own V4 callback system for the Gas Tank. Here's how the GasTankV4 contract receives deposit notifications:

How It Works

  1. Payment Created: A deposit payment is created with merchant = GasTank contract address

  2. User Sends USDT: User sends USDT to the computed payment address

  3. Payment Processed: MakaPay calls factory.process() with callback data

  4. Callback Triggered: GasTank's onPaymentReceived() is called

  5. Balance Updated: User's Gas Tank balance is credited automatically

GasTank Implementation

Key Security Pattern

Notice how the GasTank verifies the caller:

This is critical. Since anyone can call your onPaymentReceived() function, you must verify that the caller is a legitimate payment wallet. The CREATE2 computation ensures only the correct wallet can produce a matching address.


Use Case Examples

1. Automated Subscription Service

2. NFT Minting on Payment

3. Escrow Release

4. DAO Treasury Deposits


CREATE2 Deterministic Addresses

How Address Computation Works

V4 uses CREATE2 to compute payment addresses before any contract is deployed:

Why This Matters

  1. Pre-Computed: Address is known before deployment

  2. Deterministic: Same inputs always produce same address

  3. Frontrun Resistant: Fee amount is part of the salt (V4 upgrade)

  4. Cross-Chain: Same address on all EVM chains

Computing Addresses Off-Chain


V4 Contract Reference

PaymentWalletFactoryV4

The main entry point for all payment operations.

computeAddress()

Pre-computes the payment wallet address.

process()

Processes a payment with the committed fee. Use for normal payments.

Parameters:

  • callbackData: If non-empty and merchant is a contract, triggers onPaymentReceived()

processNoFee()

Processes without taking fee. Use for:

  • Underpayments

  • Wrong token recovery

  • Gas Tank scenarios

getWalletStatus()

Check if a wallet exists and its balance.


PaymentWalletV4

Minimal proxy wallet that receives and forwards payments.

execute()

Called by factory only. Transfers funds and optionally triggers callback.


Security Considerations

1. Always Verify the Caller

Your onPaymentReceived() can be called by anyone. Always verify:

2. Handle Reentrancy

Use nonReentrant modifier if your callback updates state:

3. Validate Token Address

Don't blindly trust the token parameter:

4. Callback Failures Revert Everything

If your callback reverts, the entire payment transaction reverts. Make sure your callback logic is robust:


Integration Checklist

Before going live with smart contract integration:


Deployed Contract Addresses

MakaChain Mainnet (Chain ID: 777178)

Contract
Address

PaymentWalletFactoryV4

0xCB45Df5057b9a287F9b95Af7ccdC49A1C9F2fcfA

PaymentWalletV4 Implementation

0x0e77A0A5845C49EbC8EEA521024b5a04F7B0E20B

GasTankV4

0xE94EB77a80BddD3a1c1813ed17894af0a3837d2C

USDT

0x30C28E393E0732335235685B345c95E6465Ad8A5

Other Chains

Factory and implementation addresses are identical across all supported chains (Ethereum, Polygon, BSC) due to CREATE2 deployment.


Need Help?

  • Technical Support: [email protected]

  • Documentation: https://docs.makapay.io

  • GitHub: https://github.com/makapay

Last updated