Gasless Swap is a decentralized application (dApp) that enables users to swap between two ERC-20 tokens—BuildguidlToken (BGT) and SuperToken (SPT)—with a 2% fee, using EIP-2612 "permit" signatures for gasless approvals. Users do not need ETH to approve or swap; they simply sign a message, and a backend relayer submits the transaction on-chain.
- Truly Gasless Swaps: Users swap tokens without paying gas for approvals or swaps, thanks to EIP-2612 permits and a backend relayer.
- EIP-2612 Permit Integration: Uses off-chain signatures for token approvals, enabling a seamless, gasless user experience.
- 2% Swap Fee: Each swap charges a 2% fee, deducted from the input amount.
- Instant 1:1 Swaps: Swap between BGT and SPT instantly at a 1:1 rate (minus fee).
- Open Minting: Both tokens can be minted by anyone, with per-transaction and total supply caps.
- Swap History: Users can view their recent swaps directly in the UI.
- Modern UI: Built with Next.js, RainbowKit, Wagmi, and Typescript.
- Smart Contracts: Written in Solidity, deployed via Foundry scripts.
- Next.js App: Provides a swap interface, token minting, and swap history.
- Custom Hooks: For contract reads/writes and EIP-2612 permit signing.
- No ETH Required: Users interact without holding ETH.
- Node.js/Express Relayer: Receives signed permit and swap requests, submits them to the SwapContract on-chain, and logs swap history.
- Ethers.js: For contract interaction and transaction signing.
- SwapContract.sol: Handles swaps, fees, and gasless permit logic.
- BuildguidlToken.sol & SuperToken.sol: ERC-20 tokens with EIP-2612 permit and open minting.
SwapContract.sol: Swaps BGT ↔ SPT at 1:1 minus a 2% fee, using EIP-2612 gasless approvals. Only the contract owner can withdraw tokens. Emits events for debugging and tracking.BuildguidlToken.sol&SuperToken.sol: ERC-20 tokens with EIP-2612 permit, open minting (with per-tx and total supply caps).IERC20Permit.sol: Interface for ERC-20 tokens supporting EIP-2612 permit.
- Node (>= v20.18.3)
- Yarn (v1 or v2+)
- Git
- Install dependencies:
yarn install
- Run a local network:
Starts a local Ethereum network using Foundry. Customize in
yarn chain
packages/foundry/foundry.toml. - Deploy contracts:
Deploys all contracts (tokens and swap contract) to the local network.
yarn deploy
- Start the frontend:
Visit your app at
yarn start
http://localhost:3000. - Run smart contract tests:
yarn foundry:test
- Edit smart contracts in
packages/foundry/contracts - Edit frontend homepage at
packages/nextjs/app/page.tsx - Edit deployment scripts in
packages/foundry/script
- Mint Tokens: Users mint BGT or SPT to their wallet (with per-tx and total supply caps).
- Sign Permit: When swapping, users sign an EIP-2612 permit message (off-chain, no gas).
- Swap: The backend relayer submits the swap transaction using the permit, paying the gas.
- Receive Tokens: Users receive the output token minus the 2% fee.
- View History: Users can view their recent swaps in the UI.
- Enables gasless token approvals via off-chain signatures.
- The relayer submits the signed permit and swap in a single transaction.
- The backend service receives the signed permit and swap request.
- Submits the transaction to the SwapContract, paying the gas.
- Logs the swap in the database for history display.
- BuildguidlToken (BGT):
- ERC-20 with EIP-2612 permit
- 1 billion max supply, 10,000 max mint per tx
- SuperToken (SPT):
- ERC-20 with EIP-2612 permit
- 1 billion max supply, 10,000 max mint per tx
We welcome contributions to Gasless Swap!
- Fork the repo and create a feature branch.
- Submit a pull request with a clear description of your changes.
- For major changes, open an issue first to discuss what you'd like to change.