Bridged

A gasless 2-way Ethereum↔Tron bridge with 1inch Fusion+, hashlock timelocks.

Bridged

Created At

Unite Defi

Project Description

I built a fully end-to-end, cross-chain atomic swap system that lets me bridge my own ERC-20 tokens on Ethereum’s Sepolia testnet to TRC-20 tokens on the Tron Nile testnet—and back again—without trusting any centralized intermediary. On the front end, I connect my MetaMask and TronLink wallets, then initiate a swap by locking tokens into a hash-time-lock contract (HTLC) on one chain. Once that lock is confirmed, I switch chains and claim the corresponding tokens by revealing a shared secret. All of it happens in a single, intuitive UI flow: generate a secret, click “Lock,” and then “Claim.” The HTLC contracts enforce deadlines and cryptographic proofs so that either both sides of the swap complete or both sides refund, guaranteeing atomicity.

How it's Made

Smart Contracts

ETH_HTLC (Solidity, Hardhat) Holds ERC-20 tokens under a swapId. Functions: newSwap(bytes32 swapId, address receiver, uint256 amount, bytes32 secretHash, uint256 expiry) claim(bytes32 swapId, bytes calldata preimage) refund(bytes32 swapId) Emits Locked, Claimed, Refunded events for on-chain monitoring.

TRX_HTLC (Solidity, Tron compiler) Mirrors ETH_HTLC logic for native TRX via msg.value.

Deployment & Testing: Used Hardhat to compile, deploy, and test ETH_HTLC on Sepolia (and locally via fork). Deployed TRX_HTLC to Nile testnet using Tron’s CLI and TronWeb in scripts.

Node.js Scripts swapData.json handshake: Generates a random 32-byte secret → secretHash = keccak256(secret). Computes swapId = keccak256(abi.encodePacked(secretHash, sender, receiver, expiry)). Stores { swapId, secretHash, timelock } for both chains.

scripts/lock_eth.js Reads swapData.json. Approves ERC-20 spending. Calls newSwap(...) on ETH_HTLC. Surfaces revert reasons via contract.callStatic before sending.

scripts/lock_tron.js Reads the same swapData.json. Uses TronWeb to translate base58 → hex addresses. Calls lock(...) on TRX_HTLC with msg.value.

Key Integrations & Hacks callStatic + provider.call to pre-validate on-chain calls and decode revert messages—essential for rapid iteration on testnets. Single JSON file as a “stateless” bridge between scripts—no backend server or database needed.

.env to securely manage private keys, RPC endpoints, and contract addresses.

background image mobile

Join the mailing list

Get the latest news and updates