Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/with-ledger/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
32 changes: 32 additions & 0 deletions examples/with-ledger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
35 changes: 35 additions & 0 deletions examples/with-ledger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
This is a sample [Web3Onboard](https://github.com/blocknative/web3-onboard) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) showing how to integrate the Ledger wallet into your web3 dApp.

## Getting Started

Clone this repo

```
https://github.com/blocknative/web3-onboard.git
```

Navigate to the project directory:

```
cd examples
```

Install the dependencies:

```
yarn
```

Run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Learn More

To learn more about how you can use web3Onboard to integrate Ledger and other popular web3 wallets into your dApps, take a look at our documentation: [Web3Onboard Documentation](https://docs.blocknative.com/onboard) for more details.
7 changes: 7 additions & 0 deletions examples/with-ledger/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
22 changes: 22 additions & 0 deletions examples/with-ledger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "with-ledger",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@web3-onboard/ledger": "^2.1.6",
"@web3-onboard/react": "^2.2.4",
"next": "12.2.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.20.0",
"eslint-config-next": "12.2.3"
}
}
7 changes: 7 additions & 0 deletions examples/with-ledger/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
5 changes: 5 additions & 0 deletions examples/with-ledger/pages/api/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}
113 changes: 113 additions & 0 deletions examples/with-ledger/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Head from 'next/head'
import { init, useConnectWallet } from '@web3-onboard/react'
import ledgerModule from '@web3-onboard/ledger'
import styles from '../styles/Home.module.css'

const buttonStyles = {
borderRadius: '6px',
background: '#111827',
border: 'none',
fontSize: '18px',
fontWeight: '600',
cursor: 'pointer',
color: 'white',
padding: '14px 12px',
marginTop: '40px',
fontFamily: 'inherit'
}


const INFURA__KEY = 'cf540cb0b3b643d399e59aef4f5ac179'
const ledger = ledgerModule()

// initialize Onboard
init({
wallets: [ledger],
chains: [
{
id: '0x1',
token: 'ETH',
label: 'Ethereum',
rpcUrl: `https://mainnet.infura.io/v3/${INFURA__KEY}`
},
{
id: '0x3',
token: 'tROP',
label: 'Ropsten',
rpcUrl: `https://ropsten.infura.io/v3/${INFURA__KEY}`
},
{
id: '0x4',
token: 'rETH',
label: 'Rinkeby',
rpcUrl: `https://rinkeby.infura.io/v3/${INFURA__KEY}`
},
{
id: '0x38',
token: 'BNB',
label: 'Binance',
rpcUrl: 'https://bsc-dataseed.binance.org/'
},
{
id: '0x89',
token: 'MATIC',
label: 'Polygon',
rpcUrl: 'https://matic-mainnet.chainstacklabs.com'
},
{
id: '0xfa',
token: 'FTM',
label: 'Fantom',
rpcUrl: 'https://rpc.ftm.tools/'
}
],
appMetadata: {
name: "Web3-Onboard Demo",
icon: '<svg>My App Icon</svg>',
description: "A demo of Web3-Onboard with Ledger."
},
accountCenter: {
desktop: {
position: 'topRight',
enabled: true,
minimal: false
}
}
})



export default function Home() {
const [{ wallet, connecting }, connect, disconnect] = useConnectWallet()

return (
<div className={styles.container}>
<Head>
<title>Web3-Onboard + Ledger Demo</title>
<meta
name="description"
content="Web3-Onboard Example with Ledger Hardware Wallet"
/>
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to a demo of
<a href="https://github.com/blocknative/web3-onboard">
{' '}
Web3-Onboard + Ledger
</a>
!
</h1>
<button
style={buttonStyles}
disabled={connecting}
onClick={() => (wallet ? disconnect(wallet) : connect())}
>
{connecting ? 'connecting' : wallet ? 'disconnect' : 'connect'}
</button>
</main>
</div>
)
}
129 changes: 129 additions & 0 deletions examples/with-ledger/styles/Home.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
.container {
padding: 0 2rem;
}

.main {
min-height: 100vh;
padding: 4rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.footer {
display: flex;
flex: 1;
padding: 2rem 0;
border-top: 1px solid #eaeaea;
justify-content: center;
align-items: center;
}

.footer a {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
}

.title a {
color: #0070f3;
text-decoration: none;
}

.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}

.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}

.title,
.description {
text-align: center;
}

.description {
margin: 4rem 0;
line-height: 1.5;
font-size: 1.5rem;
}

.code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}

.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
}

.card {
margin: 1rem;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
max-width: 300px;
}

.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}

.card h2 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}

.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}

.logo {
height: 1em;
margin-left: 0.5rem;
}

@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}

@media (prefers-color-scheme: dark) {
.card,
.footer {
border-color: #222;
}
.code {
background: #111;
}
.logo img {
filter: invert(1);
}
}
26 changes: 26 additions & 0 deletions examples/with-ledger/styles/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

a {
color: inherit;
text-decoration: none;
}

* {
box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
body {
color: white;
background: black;
}
}
Loading