Skip to main content

Deployment Guide

This guide covers how to deploy the Open Pay smart contracts to BSC Testnet (or Mainnet) and configure them for your environment.

Current Testnet Deployment

All contracts are live on BSC Testnet (Chain ID 97):
These testnet contracts use mock tokens and mock price feeds. For production, you would use real token addresses and Chainlink oracle feeds.

Deploy Your Own

Prerequisites

Environment Setup

1

Clone the Repository

2

Install Dependencies

3

Configure Environment Variables

Create a .env file in the contracts directory:
Never commit your .env file to version control. The deployer private key controls the contract and all escrowed funds.
4

Deploy Contracts

Deploy to BSC Testnet:
The deployment script deploys contracts in this order:
  1. MockPriceFeed — simulated Chainlink oracle (testnet only)
  2. MockUSDT — test USDT token (testnet only)
  3. MockUSDC — test USDC token (testnet only)
  4. OpenPayPriceFeed — price aggregator
  5. OpenPayEscrow — payment escrow
After deployment, the script configures:
  • Token price feeds on OpenPayPriceFeed
  • Supported tokens on OpenPayEscrow
  • Price feed address on OpenPayEscrow
5

Verify on BscScan

Verify each contract on BscScan for public source code access:
Verification makes your contract source code publicly readable on BscScan, which builds trust with users and merchants.

Adding New Tokens

To support a new ERC-20 token for payments:
1

Configure the Price Feed

Register the token with a Chainlink price feed on the OpenPayPriceFeed contract:
2

Enable on Escrow

Mark the token as supported on the OpenPayEscrow contract:
3

Update Backend

Add the token configuration to the Open Pay backend so the API knows about the new payment option. Update the token list in the service configuration.

Switching to Mainnet

When deploying to BSC Mainnet (Chain ID 56), make these changes:
1

Use Real Token Addresses

Replace mock tokens with mainnet addresses:
2

Use Real Chainlink Feeds

Replace mock price feeds with mainnet Chainlink oracles:
Find all Chainlink BSC feeds at data.chain.link.
3

Deploy to Mainnet

4

Verify and Configure

  • Verify contracts on BscScan Mainnet
  • Configure all token price feeds
  • Set the fee recipient to your production address
  • Update the platform backend with the new contract addresses

Hardhat Configuration

Example hardhat.config.ts for BSC networks:

Troubleshooting

The Chainlink oracle data is older than the staleness threshold (default 1 hour). On testnet, mock feeds may not auto-update. Call the mock feed’s updateAnswer() to refresh the price, or increase the staleness threshold.
The token has not been registered with the price feed contract. Call priceFeed.configureToken() to register it.
The payer has not approved the escrow contract to spend their tokens. The payer must call token.approve(escrowAddress, amount) before creating a payment.
Ensure you are using the exact same compiler version and optimization settings as the deployment. Check that constructor arguments match exactly.