|
| 1 | +import Head from 'next/head' |
| 2 | +import { init, useConnectWallet } from '@web3-onboard/react' |
| 3 | +import ledgerModule from '@web3-onboard/ledger' |
| 4 | +import styles from '../styles/Home.module.css' |
| 5 | + |
| 6 | +const buttonStyles = { |
| 7 | + borderRadius: '6px', |
| 8 | + background: '#111827', |
| 9 | + border: 'none', |
| 10 | + fontSize: '18px', |
| 11 | + fontWeight: '600', |
| 12 | + cursor: 'pointer', |
| 13 | + color: 'white', |
| 14 | + padding: '14px 12px', |
| 15 | + marginTop: '40px', |
| 16 | + fontFamily: 'inherit' |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +const INFURA__KEY = 'cf540cb0b3b643d399e59aef4f5ac179' |
| 21 | +const ledger = ledgerModule() |
| 22 | + |
| 23 | +// initialize Onboard |
| 24 | +init({ |
| 25 | + wallets: [ledger], |
| 26 | + chains: [ |
| 27 | + { |
| 28 | + id: '0x1', |
| 29 | + token: 'ETH', |
| 30 | + label: 'Ethereum', |
| 31 | + rpcUrl: `https://mainnet.infura.io/v3/${INFURA__KEY}` |
| 32 | + }, |
| 33 | + { |
| 34 | + id: '0x3', |
| 35 | + token: 'tROP', |
| 36 | + label: 'Ropsten', |
| 37 | + rpcUrl: `https://ropsten.infura.io/v3/${INFURA__KEY}` |
| 38 | + }, |
| 39 | + { |
| 40 | + id: '0x4', |
| 41 | + token: 'rETH', |
| 42 | + label: 'Rinkeby', |
| 43 | + rpcUrl: `https://rinkeby.infura.io/v3/${INFURA__KEY}` |
| 44 | + }, |
| 45 | + { |
| 46 | + id: '0x38', |
| 47 | + token: 'BNB', |
| 48 | + label: 'Binance', |
| 49 | + rpcUrl: 'https://bsc-dataseed.binance.org/' |
| 50 | + }, |
| 51 | + { |
| 52 | + id: '0x89', |
| 53 | + token: 'MATIC', |
| 54 | + label: 'Polygon', |
| 55 | + rpcUrl: 'https://matic-mainnet.chainstacklabs.com' |
| 56 | + }, |
| 57 | + { |
| 58 | + id: '0xfa', |
| 59 | + token: 'FTM', |
| 60 | + label: 'Fantom', |
| 61 | + rpcUrl: 'https://rpc.ftm.tools/' |
| 62 | + } |
| 63 | + ], |
| 64 | + appMetadata: { |
| 65 | + name: "Web3-Onboard Demo", |
| 66 | + icon: '<svg>My App Icon</svg>', |
| 67 | + description: "A demo of Web3-Onboard with Ledger." |
| 68 | + }, |
| 69 | + accountCenter: { |
| 70 | + desktop: { |
| 71 | + position: 'topRight', |
| 72 | + enabled: true, |
| 73 | + minimal: false |
| 74 | + } |
| 75 | + } |
| 76 | +}) |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +export default function Home() { |
| 81 | + const [{ wallet, connecting }, connect, disconnect] = useConnectWallet() |
| 82 | + |
| 83 | + return ( |
| 84 | + <div className={styles.container}> |
| 85 | + <Head> |
| 86 | + <title>Web3-Onboard + Ledger Demo</title> |
| 87 | + <meta |
| 88 | + name="description" |
| 89 | + content="Web3-Onboard Example with Ledger Hardware Wallet" |
| 90 | + /> |
| 91 | + <link rel="icon" href="/favicon.ico" /> |
| 92 | + </Head> |
| 93 | + |
| 94 | + <main className={styles.main}> |
| 95 | + <h1 className={styles.title}> |
| 96 | + Welcome to a demo of |
| 97 | + <a href="https://github.com/blocknative/web3-onboard"> |
| 98 | + {' '} |
| 99 | + Web3-Onboard + Ledger |
| 100 | + </a> |
| 101 | + ! |
| 102 | + </h1> |
| 103 | + <button |
| 104 | + style={buttonStyles} |
| 105 | + disabled={connecting} |
| 106 | + onClick={() => (wallet ? disconnect(wallet) : connect())} |
| 107 | + > |
| 108 | + {connecting ? 'connecting' : wallet ? 'disconnect' : 'connect'} |
| 109 | + </button> |
| 110 | + </main> |
| 111 | + </div> |
| 112 | + ) |
| 113 | +} |
0 commit comments