A robust backend service that facilitates cross-chain NFT bridging between Ethereum and another blockchain network. This application listens for "Lock" events on Ethereum smart contracts, records transactions in MongoDB, and mints corresponding tokens on the destination blockchain.
- Cross-Chain Bridging: Bridge ERC-1155 tokens between Ethereum and the destination network
- Event Monitoring: Listen for "Lock" events on the Ethereum blockchain
- Automatic Minting: Process pending transactions and mint tokens on the destination chain
- Transaction Tracking: Record and monitor all bridge transactions with status updates
- Balance Checking: Query token balances across both blockchains
- Token Metadata: Serve metadata for NFTs with dynamic URL construction
- Authentication: Secure API endpoints with bearer token authentication
- Dockerized Deployment: Easily deploy using Docker with provided configurations
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: MongoDB
- Blockchain: ethers.js for Web3 interactions
- Authentication: Bearer token authentication
- Containerization: Docker with docker-compose support
- CI/CD: GitHub Actions workflow ready
- Node.js (v18+)
- Yarn v4+
- MongoDB instance
- Access to Ethereum and destination network RPCs
-
Clone the repository
git clone https://github.com/yourusername/NFTBridge-Backend.git cd NFTBridge-Backend -
Install dependencies
yarn install
-
Configure environment variables by creating
.env.localfile:MONGO_URI=mongodb://your-mongodb-connection-string PRIVATEKEY=your-wallet-private-key ETH_RPC=https://ethereum-rpc-endpoint NETWORK_RPC=https://destination-network-rpc-endpoint NFT_ETH_ADDRESS=0x...your-ethereum-nft-contract-address BRIDGE_ETH_ADDRESS=0x...your-ethereum-bridge-contract-address NFT_NETWORK_ADDRESS=0x...your-destination-network-nft-contract-address INITIAL_BEARER_TOKEN=your-initial-api-token -
Build the application
yarn build
-
Start the server
yarn start
The project includes Docker configurations for easy deployment:
# Build the Docker image
make composebuild-prod
# Run the container
make run_container
# Check container logs
make logsGET /basic/getPing: Basic ping (unrestricted)GET /basic/getSafePing: Authenticated pingPOST /basic/setBearerToken: Set new bearer tokenGET /basic/getCurrentToken: Get current bearer tokenPOST /basic/changeBearerToken: Change bearer token
GET /bridge/transactions: Retrieve bridge transaction historyGET /bridge/transactions/failed: Get failed bridge transactionsGET /bridge/transactions/pending: Get pending bridge transactionsGET /bridge/status/:txHash: Check transaction statusPOST /bridge/resolve/:ethTxHash: Manually resolve a pending transactionGET /tokens/balance: Check token balances for an addressGET /tokens/minted: View all minted tokensGET /metadata/:tokenId: Get token metadata
The system monitors Ethereum for "Lock" events, indicating tokens have been locked for transfer. It then automatically mints corresponding tokens on the destination network.
The bridge maps between the following token types:
- mediaone (ID: 44 on Ethereum, 3 on destination network)
- mediatwo (ID: 33 on Ethereum, 2 on destination network)
- mediathree (ID: 11 on Ethereum, 0 on destination network)
- mediafour (ID: 22 on Ethereum, 1 on destination network)
The application periodically checks for pending transactions and attempts to process them by minting tokens on the destination network. Failed transactions can be retried or manually resolved.
.
├── src
│ ├── app.ts # Application entry point
│ ├── blockchain # Blockchain interaction logic
│ │ ├── abis # Contract ABIs
│ │ ├── balanceTracker.ts # Token balance tracking
│ │ ├── contractFunctions.ts # Contract interactions
│ │ └── metadata.ts # NFT metadata handling
│ ├── db # Database operations
│ ├── dbcode # Database client and setup
│ ├── handlers # API route handlers
│ ├── helpers # Utility functions
│ ├── middleware # Express middleware
│ ├── routes.ts # API routes
│ └── types # TypeScript interfaces
├── utils # Docker and configuration files
├── Makefile # Build and deployment commands
└── package.json # Project dependencies
This project is configured for automated deployment using GitHub Actions. The workflow is triggered when changes are pushed to the prod or staging branches. See .github/workflows for detailed configuration.
MONGO_URI: MongoDB connection stringPRIVATEKEY: Wallet private key for signing transactionsETH_RPC: Ethereum RPC endpointNETWORK_RPC: Destination network RPC endpointNFT_ETH_ADDRESS: Ethereum NFT contract addressBRIDGE_ETH_ADDRESS: Ethereum bridge contract addressNFT_NETWORK_ADDRESS: Destination network NFT contract address
Open to PRs ☕😺
Happy coding <(0_0)