-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
63 lines (60 loc) · 2.32 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<title>Connect Wallet</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/web3modal"></script>
<script src="https://unpkg.com/evm-chains"></script>
<script src="https://unpkg.com/@walletconnect/web3-provider"></script>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
</head>
<body>
<h1>Connect Your Ethereum Wallet</h1>
<button id="connectButton">Connect Wallet</button>
<script type="text/javascript">
async function connectWallet() {
// const userId = new URLSearchParams(window.location.search).get('user_id');
const userId = 777
console.log('Button clicked')
if (window.ethereum) {
console.log('Ethereum found')
try {
const addressArray = await window.ethereum.request({
method: "eth_requestAccounts",
});
console.log('Address array:', addressArray)
const address = addressArray[0];
const response = await fetch(`http://localhost:8000/save_wallet?user_id=${userId}&address=${address}`);
console.log('Request to server sent')
console.log('Response:', response)
return {
address,
userId,
}
} catch (err) {
console.log('Error:', err)
return {
address: "",
status: "😥 " + err.message,
};
}
} else {
console.log('Ethereum not found')
return {
address: "",
status: 'lol'
}
// const accounts = await web3.eth.getAccounts();
// console.log('All accounts:', accounts)
// const address = accounts[0];
// console.log('Connected with address:', address);
//
// const userId = new URLSearchParams(window.location.search).get('user_id');
// console.log('User ID:', userId);
fetch(`http://localhost:8000/save_wallet?user_id=${userId}&address=${address}`);
}
}
document.getElementById('connectButton').addEventListener('click', connectWallet);
</script>
</body>
</html>