Skip to content

Instantly share code, notes, and snippets.

@jelilat
Last active March 8, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jelilat/d0532d7c4fab8a051bb03800ada69930 to your computer and use it in GitHub Desktop.
Save jelilat/d0532d7c4fab8a051bb03800ada69930 to your computer and use it in GitHub Desktop.
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