Skip to content

Commit e8392fe

Browse files
committed
雛形準備
1 parent e4a0246 commit e8392fe

16 files changed

Lines changed: 6680 additions & 19419 deletions

File tree

contracts/Token.sol

Lines changed: 0 additions & 78 deletions
This file was deleted.

frontend/hooks/useConnectWallet.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ethers } from 'ethers';
2+
import { useCallback } from 'react';
3+
4+
export const useConnectWallet = () => {
5+
const redirectUrl = `http://localhost:3000`
6+
7+
return {
8+
connectWallet: useCallback(async () => {
9+
const metamaskIsInstalled = window.ethereum?.isMetaMask;
10+
if (!metamaskIsInstalled) {
11+
window.location.href = `https://metamask.app.link/dapp/${redirectUrl}`;
12+
return;
13+
}
14+
try {
15+
const provider = new ethers.providers.Web3Provider(window.ethereum);
16+
await provider.send('eth_requestAccounts', []);
17+
const signer = provider.getSigner();
18+
const userAddress = await signer.getAddress();
19+
console.log(userAddress);
20+
} catch (error) {
21+
console.log('Error connecting to metamask', error);
22+
}
23+
}, []),
24+
};
25+
};

frontend/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
"start": "next start"
77
},
88
"dependencies": {
9+
"ethers": "^5.7.2",
910
"next": "latest",
1011
"react": "18.2.0",
11-
"react-dom": "18.2.0"
12+
"react-dom": "18.2.0",
13+
"autoprefixer": "^10.4.13",
14+
"postcss": "^8.4.20"
1215
},
1316
"devDependencies": {
1417
"@types/node": "^18.11.15",
1518
"@types/react": "^18.0.26",
16-
"autoprefixer": "^10.4.13",
17-
"postcss": "^8.4.20",
1819
"sass": "^1.56.2",
1920
"tailwindcss": "^3.2.4",
2021
"typescript": "^4.9.4"

frontend/pages/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import Head from 'next/head';
2+
import { useConnectWallet } from '../hooks/useConnectWallet';
23

34
export default function Home() {
5+
const { connectWallet } = useConnectWallet();
46
return (
57
<>
68
<Head>
79
<title>dapps入門</title>
810
</Head>
9-
<div>hello</div>
11+
<h1 className="text-3xl font-bold underline">
12+
<button onClick={connectWallet} className="p-2 border border-solid">connect wallet</button>
13+
</h1>
1014
</>
1115
);
1216
}

frontend/react-app-env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { MetaMaskInpageProvider } from "@metamask/providers";
2+
3+
declare global {
4+
interface Window{
5+
ethereum?:MetaMaskInpageProvider
6+
web3: any
7+
}
8+
}

frontend/styles/globals.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

frontend/tailwind.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ module.exports = {
55
// For the best performance and to avoid false positives,
66
// be as specific as possible with your content configuration.
77
],
8+
theme: {
9+
extend: {},
10+
},
11+
plugins: [],
812
};

0 commit comments

Comments
 (0)