-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
63 lines (51 loc) · 2.41 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>
<script src="https://unpkg.com/@metamask/legacy-web3@latest/dist/metamask.web3.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<meta charset="UTF-8">
<title>metamask-payment-example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<div class="btext">
<a href="#" class="btneth">Donate with MetaMask</a>
<div class="message"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script>
var tipButton = document.querySelector('.btneth')
tipButton.addEventListener('click', async function()
{
if (typeof web3 === 'undefined')
{
return renderMessage('<div>You need to install <a href=“https://metmask.io“>MetaMask </a> to use this feature. <a href=“https://metmask.io“>https://metamask.io</a></div>')
}
web3 = new Web3(window.ethereum)
window.ethereum.enable().catch(error => {
console.log(error)
})
var user_address = await web3.eth.getAccounts()
console.log(user_address[0])
web3.eth.sendTransaction(
{
to: '0x274b35a273040Ca0D1C98d3b926a82Fc148FFC75',
from: user_address[0],
},
function (err, transactionHash)
{
if (err) return renderMessage('There was a problem!: ' + err.message)
renderMessage('Thanks for the generosity!!')
})
})
function renderMessage (message)
{
var messageEl = document.querySelector('.message')
messageEl.innerHTML = message
}
</script>
</body>
</html>