Skip to content

Commit 27bd52d

Browse files
author
Abyl Ikhsanov
committed
initial commit
1 parent 11a047f commit 27bd52d

File tree

8 files changed

+930
-15
lines changed

8 files changed

+930
-15
lines changed

Diff for: package-lock.json

+831
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@types/node": "^16.18.46",
1111
"@types/react": "^18.2.21",
1212
"@types/react-dom": "^18.2.7",
13+
"ethers": "5.7",
1314
"react": "^18.2.0",
1415
"react-dom": "^18.2.0",
1516
"react-scripts": "5.0.1",
@@ -39,5 +40,9 @@
3940
"last 1 firefox version",
4041
"last 1 safari version"
4142
]
43+
},
44+
"devDependencies": {
45+
"prettier": "^3.0.2",
46+
"tailwindcss": "^3.3.3"
4247
}
4348
}

Diff for: src/App.css

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
15
.App {
26
text-align: center;
37
}
@@ -36,3 +40,5 @@
3640
transform: rotate(360deg);
3741
}
3842
}
43+
44+

Diff for: src/App.tsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
import React from 'react';
2+
import { Login } from './components/Login';
3+
24
import logo from './logo.svg';
35
import './App.css';
46

57
function App() {
68
return (
79
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
10+
<Login />
2211
</div>
2312
);
2413
}

Diff for: src/components/Login.tsx

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from "react";
2+
import { ethers } from "ethers";
3+
import "../interfaces/ether.d.ts";
4+
5+
import "../App.css";
6+
7+
export const Login = () => {
8+
const [account, setAccount] = React.useState<string>("");
9+
const [contractAddress, setContractAddress] = React.useState<string>("");
10+
const [balance, setBalance] = React.useState<string>("");
11+
12+
const connectWallet = async () => {
13+
const [address] = await window.ethereum.request({
14+
method: "eth_requestAccounts",
15+
});
16+
const provider = new ethers.providers.Web3Provider(window.ethereum);
17+
const balance = await provider.getBalance(address);
18+
setBalance(ethers.utils.formatEther(balance));
19+
setAccount(address);
20+
};
21+
22+
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
23+
setContractAddress(event.target.value);
24+
};
25+
26+
const callContractMethod = async () => {
27+
const provider = new ethers.providers.Web3Provider(window.ethereum);
28+
const contract = new ethers.Contract(
29+
contractAddress,
30+
["function setToken()"],
31+
provider.getSigner()
32+
);
33+
await contract.setToken();
34+
};
35+
36+
return (
37+
<div className="flex flex-col items-center">
38+
<button
39+
onClick={connectWallet}
40+
className="bg-blue-600 text-white px-4 py-2 rounded"
41+
>
42+
Connect Wallet
43+
</button>
44+
{account && (
45+
<div className="mt-4">
46+
<p className="text-lg">Account: {account}</p>
47+
<p className="text-lg">Balance: {balance}</p>
48+
<input
49+
type="text"
50+
className="mt-4"
51+
placeholder="Contract address"
52+
value={contractAddress}
53+
onChange={handleInputChange}
54+
/>
55+
<button
56+
onClick={callContractMethod}
57+
className="bg-blue-600 text-white px-4 py-2 rounded mt-2"
58+
>
59+
Call Contract Method
60+
</button>
61+
</div>
62+
)}
63+
</div>
64+
);
65+
};

Diff for: src/interfaces/ether.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface Ethereum {
2+
enable(): Promise<string[]>;
3+
selectedAddress: null | string;
4+
request: any;
5+
}
6+
7+
interface Window {
8+
ethereum: Ethereum;
9+
}
10+

Diff for: tailwind.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: ["./src/**/*.{html,js,tsx}"],
4+
theme: {
5+
extend: {},
6+
},
7+
plugins: [],
8+
}
9+

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"jsx": "react-jsx"
2222
},
2323
"include": [
24-
"src"
24+
"src/**/*"
2525
]
2626
}

0 commit comments

Comments
 (0)