Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useDapp connect metamask example

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

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

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

ReactDOM.render(
  <DAppProvider config={config}>
    <App />
  </DAppProvider>,
  document.getElementById('root')
)

function App() {
  const { account, deactivate } = useEthers()
  const etherBalance = useEtherBalance(account)

  return (
    <div>
      <MetamaskConnect />
      {account && <button onClick={() => deactivate()}>Disconnect</button>}
      {etherBalance && (
        <div className="balance">
          <br />
          Balance:
          <p className="bold">{formatEther(etherBalance)}</p>
        </div>
      )}
    </div>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: square brackets javascript object key 
Javascript :: How to Solve the Parking Lot Challenge in JavaScript 
Javascript :: true type of javascript 
Javascript :: Looping through array, fetching tweets and returning new reversed array javascript react 
Javascript :: prisma bytes 
Javascript :: Update A Request() Property 
Javascript :: Get year from user entered date in javascript 
Javascript :: docker healthcheck express 
Javascript :: Exporting Objects with the Exports Object in electron 
Javascript :: var sumArray = function(arr) {}; 
Javascript :: mongoose export collection 
Javascript :: backbone view 
Javascript :: how to close bootstrap modal after save 
Javascript :: How many options are there to climb a ladder with N 
Javascript :: how to convert javascript to typescript 
Javascript :: how to get event from iframe 
Javascript :: hide and show button react js 
Javascript :: convert milliseconds to dd/mm/yyyy javascript 
Javascript :: classes in js 
Javascript :: moment max 
Javascript :: how to use npm package in javascript 
Javascript :: sort include sequelize 
Javascript :: chatbot js 
Javascript :: shopify liquid logic 
Javascript :: js add obj prop dynamically 
Javascript :: javascript prototype chaining 
Javascript :: javascript for...of with Maps 
Javascript :: ajax introduction 
Javascript :: Knockout js custom bindings 
Javascript :: theme ui with react 17 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =