Skip to content

thronecloud/meson-python-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meson Bridge Demo - Ethereum to Tron USDT Bridge

A simple Python script that implements all steps from the Meson API tutorial to bridge USDT from Ethereum to Tron on mainnet.

Features

  • ✅ 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

Installation

  1. Install Python dependencies:
pip install -r requirements.txt

Usage

Set Environment Variables

Required:

A .env file with these two values :- PRIVATE_KEY=1f19348f4556f372b0ac6a92607d8d2233f4fba0f139fb8b09fb437c305d01d0 TRON_RECIPIENT=TF5zKmVKHftUWEMvMnfw9MKQ2WUAKgBioE

Run the Bridge

python meson_bridge_demo.py

What the Script Does

The script implements all 5 steps from the Meson API tutorial:

  1. Get Price - Retrieves fee data for the cross-chain swap
  2. Encode Swap - Encodes the swap parameters and gets signing data
  3. Sign Data - Signs the swap data using your private key
  4. Submit Swap - Submits the signed swap to Meson relayer
  5. Check Status - Monitors the swap status until completion

Important Notes

Security

  • Never commit your private key to version control
  • Use environment variables for sensitive data
  • Test with small amounts first

Prerequisites

  • 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

Monitoring

  • The script monitors swap status for 5 minutes by default
  • You can also monitor manually at: https://explorer.meson.fi/swap/{swap_id}

Example Output

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...

Troubleshooting

Common Issues

  1. "Please set your PRIVATE_KEY environment variable"

    • Make sure to export your private key without the '0x' prefix
  2. Network errors

    • Check your internet connection
    • Verify mainnet is accessible
    • Ensure you have USDT and sufficient ETH on Ethereum chain
  3. Insufficient balance

    • Ensure you have enough ETH for gas fees
    • Ensure you have at least 10 USDT to bridge
  4. Invalid signature

    • Verify your private key is correct
    • Check that the address has the required permissions

Customization

You can modify the script to:

  • Change the bridge amount (modify amount in swap_params)
  • Bridge different tokens (modify from and to in swap_params)
  • Use different chains (check Meson documentation for supported chains)
  • Adjust monitoring duration (change monitor_duration parameter)

Links

About

Meson Python API Implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages