Bridge tokens securely across Ethereum and Tron using hashlocks & timelocks - powered by 1inch.
This project is a cross-chain atomic swap system that allows secure and trustless exchange of tokens between Ethereum and Tron networks. It is based on Hashed Timelock Contracts (HTLC), which ensure that funds are only transferred if a specific secret is revealed within a set time limit. This mechanism removes the need for a trusted third party and allows users to swap tokens across chains in a decentralized and transparent way.
The process begins with the generation of a secret string, which is then hashed using Keccak256 to produce a hashlock. This hashlock is used as a condition in both Ethereum and Tron smart contracts. On the Ethereum side, a contract called EscrowSrc is deployed using a resolver contract. The user approves and locks 10 USDC into this EscrowSrc contract, where the funds remain locked under the hashlock and a timelock.
Once the Ethereum user calls the withdraw function with the correct secret, the secret is revealed publicly on the Ethereum blockchain. This revealed secret can now be used to unlock funds on the Tron network. Using TronWeb, a corresponding EscrowDst contract is deployed on Tron with the same hashlock and timelock. The user then calls the withdraw function on the Tron side using the same secret to unlock and claim the tokens.
The script includes logging of token balances on both Ethereum and Tron before and after the swap process. This helps verify that the tokens were correctly deducted from Ethereum and added to the Tron wallet, confirming a successful cross-chain swap.
The project uses Solidity for the Ethereum contracts and TronWeb for the Tron contracts. Ethers.js is used for Ethereum interactions, and TronWeb handles all Tron-side operations. Environment variables are used to manage private keys and RPC URLs securely.
Overall, this system serves as a working prototype for secure cross-chain swaps using HTLC. It can be extended into a larger system such as a decentralized exchange or integrated into other blockchain applications that require atomic cross-chain functionality.
This project is a cross-chain atomic swap between Ethereum and Tron using Hashed Timelock Contracts (HTLC). I used Solidity smart contracts on both chains to securely lock and release tokens based on a shared secret and timelock mechanism.
The script is written in Node.js using Ethers.js for Ethereum and TronWeb for Tron. It automates the entire flow: deploying escrow contracts, approving and locking tokens on Ethereum, waiting for the secret to be revealed via an on-chain event, then unlocking tokens on Tron using the same secret. Balances are printed before and after the swap to verify correctness.
Key parts include a polling mechanism to detect events, manual log parsing to extract deployed addresses, and full control of both chains without needing any bridge infrastructure.