Smart Contracts
Explore the smart contract architecture that handles payments and PNPL.
Contract Overview
Merso uses a set of audited smart contracts to handle payment processing, NFT escrow, and PNPL payment schedules on-chain.
Payment Router
Routes payments to the correct destination and handles fee distribution.
Escrow Contract
Holds NFTs during PNPL payment periods until full payment is complete.
Payment Schedule
Manages PNPL installment tracking and automatic payment collection.
EVM Contracts
| Contract | Purpose | Standard |
|---|---|---|
MersoPaymentRouter |
Main entry point for all payments | Custom |
MersoEscrow |
NFT escrow for PNPL | ERC-721 Receiver |
MersoPNPL |
Payment schedule management | Custom |
TokenApproval |
ERC-20 approval helper | ERC-20 |
All Merso contracts are verified on block explorers. Contact us for specific contract addresses on your target chain.
PNPL Smart Contract Flow
interface IMersoPNPL {
// Initialize a PNPL payment plan
function initiatePlan(
address buyer,
address nftContract,
uint256 tokenId,
uint256 totalAmount,
uint8 installments
) external returns (uint256 planId);
// Process a weekly payment
function processPayment(uint256 planId) external;
// Get plan status
function getPlanStatus(uint256 planId)
external view returns (
uint256 paid,
uint256 remaining,
uint8 completedInstallments
);
}
Token Approval Process
Before making payments with ERC-20 tokens, users must approve the Payment Router contract to spend tokens on their behalf.
// Step 1: Get approval transaction from Merso API
const approvalData = await fetch('/api/approval', {
method: 'POST',
body: JSON.stringify({
token: 'USDC',
amount: '100000000', // 100 USDC (6 decimals)
chain_id: '137'
})
});
// Step 2: User signs the approval transaction
const txHash = await wallet.sendTransaction(approvalData.transaction);
// Step 3: Wait for confirmation
await provider.waitForTransaction(txHash);
For security, we recommend approving only the exact amount needed rather than unlimited approvals. The Merso API generates minimal approval transactions by default.
Solana Programs
On Solana, Merso uses native programs for payment processing with the same functionality as EVM contracts.
| Program | Purpose |
|---|---|
merso_payment |
Payment routing and fee distribution |
merso_escrow |
NFT escrow using PDAs |
merso_pnpl |
Payment schedule with SPL Token support |
Gas Optimization
-
✓
Batched OperationsMultiple operations combined into single transactions where possible.
-
✓
Efficient StoragePacked storage layouts minimize on-chain storage costs.
-
✓
Gas EstimationAPI provides accurate gas estimates before transaction submission.