Skip to main content


To start working with useDapp you need to have a working React environment.

To get started, add the following npm package @usedapp/core and its peer dependency in your project:

npm install @usedapp/core ethers


Below is a simple example:

import React from 'react'
import ReactDOM from 'react-dom'

import { Mainnet, DAppProvider, useEtherBalance, useEthers, Config, Goerli } from '@usedapp/core'
import { formatEther } from '@ethersproject/units'
import { getDefaultProvider } from 'ethers'

const config: Config = {
readOnlyChainId: Mainnet.chainId,
readOnlyUrls: {
[Mainnet.chainId]: getDefaultProvider('mainnet'),
[Goerli.chainId]: getDefaultProvider('goerli'),

<DAppProvider config={config}>
<App />

const ConnectButton = () => {
const { account, deactivate, activateBrowserWallet } = useEthers()
// 'account' being undefined means that we are not connected.
if (account) return <button onClick={() => deactivate()}>Disconnect</button>
else return <button onClick={() => activateBrowserWallet()}>Connect</button>

function App() {
const { account, chainId } = useEthers()
const etherBalance = useEtherBalance(account)
if (chainId && !config.readOnlyUrls[chainId]) {
return <p>Please use either Mainnet or Goerli testnet.</p>

return (
<ConnectButton />
{etherBalance && (
<div className="balance">
<br />
<p className="bold">{account}</p>
<br />
<p className="bold">{formatEther(etherBalance)}</p>

A more comprehensive example is available here, with source code available here. Let's now go through the provided example in more details.


The first thing you need to do is set up DAppProvider with optional config and wrap your whole App in it. You can read about config here.

<App /> {/* Wrap your app with the Provider */}

Connecting to a browser wallet

Then you need to activate the provider using activateBrowserWallet. It's best to do when the user clicks the "Connect" button.

  export function App() {
const { activateBrowserWallet, account } = useEthers()
return (
<button onClick={() => activateBrowserWallet()}>Connect</button>
{account && <p>Account: {account}</p>}

After the activation (i.e. user connects to a wallet like MetaMask) the component will show the user's address.

If you need to use another connector than a browser wallet, use the activate method from useEthers. See the web3-react doc for that one.