├── .DS_Store ├── README.md ├── swap-demo-tutorial-part-1 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-2 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-3 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-4 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-5 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-6 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-7 ├── index.html ├── index.js └── style.css ├── swap-demo-tutorial-part-8 ├── index.html ├── index.js └── style.css └── swap-demo-tutorial-part-9 ├── index.html ├── index.js └── style.css /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xProject/swap-demo-tutorial/bdb9e5a829b8b21ca0422ebdbbbffacb0822b79a/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **Note** 2 | > 📣 All API requests require a 0x API key. Legacy code examples may contain requests without API keys. Follow [this guide](https://0x.org/docs/introduction/getting-started) for how to get a live API key and use it for any 0x products. 3 | 4 | 5 | > [!WARNING] 6 | > 0x API v1 was sunset on April 11, 2025. Please migrate to v2. For details, see the [migration guide](https://0x.org/docs/upgrading). See the [latest v2 examples](https://github.com/0xProject/0x-examples/tree/main?tab=readme-ov-file#v2-latest). 7 | 8 | 9 | # How to Build a Simple Token Swap DApp using the 0x Swap API 10 | 11 | 12 | Learn how to build a token swapping dapp, similar to a simple [Matcha.xyz](https://matcha.xyz/), using the [0x /swap API endpoint](https://docs.0x.org/0x-api-swap/api-references/get-swap-v1-quote). 13 | 14 | This app [aggregates liquidity across the greater DEX ecosystem using 0x](https://docs.0x.org/introduction/introduction-to-0x#the-0x-ecosystem) to surfaces the best price to the user and allow them to easily settle their trades! 15 | 16 | ## Follow Along to Learn 17 | 18 | * 💦 What is liquidity aggregation? 19 | * 🪟 Query + Display an ERC20 token list 20 | * ♻️ Use @0xProject API's /swap endpoint 21 | * 🧱 Build a Swap Dapp with Metamask and Web3.js 22 | 23 | ## Video and Written Tutorial 24 | 25 | * 🎥 Watch Video Walk-Through: https://www.youtube.com/watch?v=tVvZ1ivp4X0 26 | * 📖 Full Written Tutorial: https://0x.org/docs/0x-swap-api/guides/how-to-build-a-token-swap-dapp-with-0x-api 27 | * The repo is broken up by parts which correspond to parts in the written tutorial above ☝️ Each part builds upon the previous one. 28 | * Part 1. Walk-through Starter Code 29 | * Part 2. Connect to MetaMask 30 | * Part 3. Create a Modal for the Token List 31 | * Part 4. Fetch and Display Token List from CoinGecko API 32 | * Part 5. Display Selected Token Image and Symbol in Swap Box 33 | * Part 6. Get Price 34 | * Part 7. Get Quote 35 | * Part 8. Set a Token Allowance 36 | * Part 9. Perform the Swap 37 | 38 | ## Further Examples 39 | 40 | To find more demo apps, check out the official [0x examples repo](https://github.com/0xProject/0x-examples). 41 | 42 | Try out - 43 | 44 | - [Swap API Demo App (Next.js)](https://github.com/0xProject/0x-nextjs-demo-app/tree/main) 45 | - [Tx Relay API Demo App (Next.js App Router)](https://github.com/0xProject/0x-examples/tree/main/tx-relay-next-app) 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /swap-demo-tutorial-part-1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |