
This will take you to a page where you can select the tokens you want to add to the pool. Make sure to choose the correct token pairs and amounts.
To get the embed code, go to the Uniswap dashboard and click on the "Embed" button. This will generate a code snippet that you can copy and paste into your website.
Uniswap offers a range of customization options for the embed code, including the ability to change the color scheme and add a logo.
Swap Options
You can swap tokens using Uniswap in two ways. In the first scenario, ETH is sent to the exchange contract, which is automatically converted into ERC20 tokens.
Etherscan shows that 0.05 ETH has been deposited into the exchange contract and converted into 5 ERC20 tokens. These tokens are then transferred to the buyer's wallet.
Uniswap also allows you to swap between two ERC20 tokens, as demonstrated by swapping our deployed ERC20 token for 10 LINK tokens.
Customizing Default List

You can offer a different set of tokens in the widget by providing a custom tokenList parameter. This allows you to browse popular token lists and find one that suits your needs, then pass the URL as a parameter.
You can create your own token list, which is recommended if you want to use the same token list in multiple places throughout your application or community. To do this, create a full token list and host it at your own URI.
Alternatively, you can construct a custom token list inline as an array of tokens. This option lets you skip deployment, hosting, and versioning of a full URI token list. The schema for this is equivalent to the tokens array from the tokenlist JSON schema.
You can add Layer 2 tokens to the token list by adding an extension field. This requires checking out the GitHub issue for details.
Please note that the swap widget only enforces metadata validation on remotely hosted token lists, not on token list data passed as a literal value to the widget.
Swap Widget States
The Swap Widget States are crucial to understanding how the swap widget functions. There are two main states, and they're determined by whether the user has connected a wallet.
Before wallet connection, the widget is not fully functional. It will use the JSON-RPC endpoint to fetch token price data and provide trade quotes, but submitting transactions will be disabled.
After wallet connection, the swap widget is fully functional. The user can fetch trade quotes and submit swap transactions using the JSON-RPC endpoint and web3 provider from their connected wallet.
In other words, connecting a wallet unlocks the widget's full potential.
Here's a quick summary of the two states:
Swap Page
The Swap Page is a crucial part of any cryptocurrency trading platform. This is where you can initiate a swap transaction, exchanging one currency for another.
One of the key parameters on the Swap Page is the input currency, which is the currency that will be swapped for the output currency. This is specified using the address of the currency.
The output currency is also a critical parameter, and it can be specified using either the address of the currency or the abbreviation "ETH" for Ether. The slippage, or maximum amount of currency that can be lost during the transaction, is also adjustable.
The Swap Page allows you to set a custom token amount to buy or sell, which is useful if you have a specific amount in mind. You can choose to set this amount for either the input or output currency.
Here are the key parameters on the Swap Page:
Swap Exact Input
Swap Exact Input is a reliable way to trade cryptocurrencies, ensuring you receive a minimum amount of the desired token.
This method involves transferring a specified amount of one token, such as WETH, from the sender to the contract, and then executing the swap using the router's exactInputSingle method.
The contract approves the router to spend the transferred amount, setting up the swap parameters for a smooth transaction.
The swap parameters are carefully set up to guarantee a minimum amount of the desired token, DAI, is received in the swap.
Interfaces
In the world of swaps, interfaces play a crucial role in facilitating interactions between different systems.
To interact with the Uniswap V3 SwapRouter, you'll need an instance of the ISwapRouter02 interface, which is used to manage swaps.
A router is essentially a middleman that helps connect different parties for a smooth exchange.
Here are some key interfaces you'll encounter in the world of swaps:
- Router: An instance of the ISwapRouter02 interface used to interact with the Uniswap V3 SwapRouter.
- WETH: An instance of the IERC20 interface representing the WETH token.
- DAI: An instance of the IERC20 interface representing the DAI token.
Advanced Topics
Token exchange on Uniswap can be quite complex, but one key aspect to consider is that Uniswap uses a unique liquidity pool system, where liquidity providers earn fees on their contributed assets. This system allows for high liquidity and fast trading execution.
To embed the Uniswap token exchange code on your website, you'll need to use a specific JavaScript library, which can be obtained from the Uniswap website. This library provides a robust and customizable solution for integrating Uniswap into your application.
Web3 Provider
You can omit the provider prop if your app doesn't maintain its own web3 provider, as the widget will use built-in wallet connection functionality for WalletConnect and MetaMask.
The widget will use the provider object passed into the provider prop, which can be any EIP-1193 provider, including ethers and web3.js provider objects.
If you already have a web3 provider, you can pass it directly into the provider prop, and the widget will work seamlessly with it.
The widget will also work with providers returned from web3-react or wagmi, both of which are ethers providers.
However, when using [email protected], you'll need to use the signer's provider instead of the fallback provider.
To intercept the wallet connection flow, you can pass a handler returning false to the onConnectWalletClick prop, which is triggered when the "Connect wallet" button is clicked.
This is especially useful if you maintain a web3 provider on your app, as you can build your own flow using libraries like web3-react, BlockNative’s Onboard, or Aragon’s useWallet().
Create Token Exchange Contract
To create a token exchange contract in Uniswap, you'll need to deploy the Uniswap Factory contract. The Uniswap Factory contract has been deployed on Rinkeby at 0xf5d915570bc477f9b8d6c0e980aa81757a3aac36.
The ABI and code for the contract can be found on the Etherscan page, specifically in the "Code" section. This is where you'll get the information you need to create a new exchange contract for your ERC20 token.
To create the exchange contract, you'll need to send a signed transaction to the deployed Uniswap Factory contract in the Rinkeby network. You can choose to run a local Ethereum client or use Infura to send the transaction.
For simplicity, the example uses Infura to send signed raw transactions. The Javascript file script/1.create.exchange.js is used to create the exchange contract, and it requires the ERC20 token contract address as a parameter.
Running the Javascript file with Node.js will output the result, which should look like the example output provided. If you encounter an error, it might be due to Infura blocking methods that require private keys, such as eth_sendTransaction.
Infura has a specific policy against storing private keys, so it's essential to be aware of this limitation. You can find more information about Infura's policy on raineorshine's github.
Uniswap Integration
To integrate your token into Uniswap, you'll need to create an exchange contract. This can be done by sending a signed transaction to the Uniswap Factory contract on the Rinkeby network.
You can use a local Ethereum client like Geth or Parity, or send the transaction through Infura to sign the transaction with your private key. The Uniswap Factory contract's ABI and code can be found on the Etherscan page.
To create the exchange contract, you'll need to run a Javascript file called script/1.create.exchange.js with Node.js. This file takes the ERC20 token contract address as a parameter.
The output of running this script should look like a specific error message if the underlying JSON-RPC method is not supported by Infura. This can happen if the method requires Infura to store private keys, which it doesn't support.
Once the exchange contract is created, you can use another Javascript file called script/2.get.exchange.address.js to query its address. This verifies that the exchange contract has been successfully created for your ERC20 token.
The Swap Page in Uniswap has several parameters that can be adjusted, including inputCurrency, outputCurrency, slippage, exactAmount, and exactField. These parameters can be used to customize the token swap.
Here are the Swap Page parameters with their descriptions:
You can use these parameters to customize the token swap on the Swap Page in Uniswap.
Frequently Asked Questions
How do I add a token to Uniswap?
To add a token to Uniswap, follow these steps: create an exchange for your token, add liquidity to the pool, and verify your token listing. Start by setting up your token's exchange on Uniswap to get started.
Sources
- https://docs.uniswap.org/sdk/swap-widget/guides/getting-started
- https://docs.uniswap.org/contracts/v1/guides/custom-linking
- https://blockchain.oodles.io/dev-blog/swap-tokens-on-uniswap-v3/
- https://blog.oceanprotocol.com/the-developers-guide-to-uniswap-48fcf6e9ee1e
- https://stackoverflow.com/questions/tagged/uniswap
Featured Images: pexels.com