Last active
March 8, 2022 12:04
-
-
Save jelilat/d0532d7c4fab8a051bb03800ada69930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './App.css'; | |
import { useState } from 'react'; | |
import { providers, ethers } from 'ethers'; | |
import detectEthereumProvider from '@metamask/detect-provider'; | |
import { SwapWidget } from '@uniswap/widgets'; | |
const infuraId = process.env.REACT_APP_INFURA_ID; | |
const jsonRpcEndpoint = `https://mainnet.infura.io/v3/${infuraId}`; | |
const jsonRpcProvider = new providers.JsonRpcProvider(jsonRpcEndpoint); | |
const provider = new ethers.providers.Web3Provider(jsonRpcProvider); | |
function App() { | |
const [account, setAccount] = useState({ | |
address: '', | |
provider: provider, | |
}) | |
async function connectWallet() { | |
const ethereumProvider = await detectEthereumProvider(); | |
if (ethereumProvider) { | |
const accounts = await window.ethereum.request({ | |
method: 'eth_requestAccounts', | |
}) | |
const address = accounts[0]; | |
setAccount({ | |
address: address, | |
provider: ethereumProvider | |
}) | |
} | |
} | |
return ( | |
<div className="App"> | |
<div> | |
<button onClick={connectWallet}>Connect Wallet</button> | |
</div> | |
<div className="Uniswap"> | |
<SwapWidget | |
provider={account.provider} | |
JsonRpcEndpoint={jsonRpcEndpoint} /> | |
</div> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment