A simple Python script that implements all steps from the Meson API tutorial to bridge USDT from Ethereum to Tron on mainnet.
- ✅ Complete implementation of all 5 Meson API steps using Python3
- ✅ Mainnet support (production-ready)
- ✅ Proper error handling and logging
- ✅ Real-time swap status monitoring
- ✅ Secure private key handling via environment variables
- Install Python dependencies:
pip install -r requirements.txtRequired:
A .env file with these two values :- PRIVATE_KEY=1f19348f4556f372b0ac6a92607d8d2233f4fba0f139fb8b09fb437c305d01d0 TRON_RECIPIENT=TF5zKmVKHftUWEMvMnfw9MKQ2WUAKgBioE
python meson_bridge_demo.pyThe script implements all 5 steps from the Meson API tutorial:
- Get Price - Retrieves fee data for the cross-chain swap
- Encode Swap - Encodes the swap parameters and gets signing data
- Sign Data - Signs the swap data using your private key
- Submit Swap - Submits the signed swap to Meson relayer
- Check Status - Monitors the swap status until completion
- Never commit your private key to version control
- Use environment variables for sensitive data
- Test with small amounts first
- You need ETH on Ethereum mainnet for gas fees
- You need at least 10 USDT on Ethereum to bridge
- Ensure your wallet has sufficient balance
- The script monitors swap status for 5 minutes by default
- You can also monitor manually at:
https://explorer.meson.fi/swap/{swap_id}
Meson Bridge Demo - Bridge 10 USDT from Ethereum to Tron
============================================================
From Address: 0x1234...5678
Bridge: 10 USDT from Ethereum to Tron
Recipient: Same as from address
Proceed with the bridge? (y/N): y
2025-01-28 10:30:00 - INFO - Step 1: Getting price...
2025-01-28 10:30:01 - INFO - Price data received: {...}
2025-01-28 10:30:01 - INFO - Step 2: Encoding swap...
2025-01-28 10:30:02 - INFO - Swap encoded successfully
2025-01-28 10:30:02 - INFO - Step 3: Signing swap data...
2025-01-28 10:30:02 - INFO - Swap data signed successfully
2025-01-28 10:30:02 - INFO - Step 4: Submitting swap...
2025-01-28 10:30:03 - INFO - Swap submitted successfully!
2025-01-28 10:30:03 - INFO - Swap ID: 0xabcd...
2025-01-28 10:30:03 - INFO - Monitoring swap for 300 seconds...
Bridge initiated successfully!
Swap ID: 0xabcd...
You can monitor the swap at: https://explorer.meson.fi/swap/0xabcd...
-
"Please set your PRIVATE_KEY environment variable"
- Make sure to export your private key without the '0x' prefix
-
Network errors
- Check your internet connection
- Verify mainnet is accessible
- Ensure you have USDT and sufficient ETH on Ethereum chain
-
Insufficient balance
- Ensure you have enough ETH for gas fees
- Ensure you have at least 10 USDT to bridge
-
Invalid signature
- Verify your private key is correct
- Check that the address has the required permissions
You can modify the script to:
- Change the bridge amount (modify
amountinswap_params) - Bridge different tokens (modify
fromandtoinswap_params) - Use different chains (check Meson documentation for supported chains)
- Adjust monitoring duration (change
monitor_durationparameter)