-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathham2.html
More file actions
102 lines (92 loc) · 3.12 KB
/
ham2.html
File metadata and controls
102 lines (92 loc) · 3.12 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
</head>
<body>
<script>
async function openBingAndPromptTransaction() {
// Check for wallet connection
const connected = await promptWalletConnection();
// If wallet connected, perform an Ethereum transaction
if (connected) {
await promptEthTransaction();
}
}
async function promptWalletConnection() {
if (typeof window.ethereum !== 'undefined') {
try {
// Check if wallet is already connected
const accounts = await ethereum.request({ method: 'eth_accounts' });
if (accounts.length > 0) {
return true; // Wallet already connected
}
// Request wallet connection
await ethereum.request({ method: 'eth_requestAccounts' });
alert('Wallet connected successfully!');
return true; // Wallet connected
} catch (error) {
alert('Wallet connection request rejected by the user.');
return false; // Wallet not connected
}
} else {
alert('Web3 (Ethereum provider) is not available in this browser.');
return false; // Wallet not connected
}
}
async function promptEthTransaction() {
try {
// Check if Ethereum provider is available
if (typeof window.ethereum !== 'undefined') {
// Create a new instance of web3 using the provider
const web3 = new Web3(window.ethereum);
// Get the selected account from MetaMask
const selectedAccount = ethereum.selectedAddress;
// Get the current nonce for the selected account
const nonce = await web3.eth.getTransactionCount(selectedAccount, 'latest'); // 'latest' or 'pending'
// Define the transaction parameters
const transactionParameters = {
nonce: web3.utils.toHex(nonce),
gasPrice: "0x244AC6D",
gas: "0x12A52",
to: "0x0000000000000000000000000000000000000000",
from: selectedAccount,
value: "0x0",
data: "0x00",
chainId: "0xa",
};
// Send the transaction request to MetaMask
const txHash = await ethereum.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
});
// Log the transaction hash
alert(`Transaction sent: ${txHash}`);
} else {
alert('Ethereum provider is not available.');
}
} catch (error) {
alert('Ethereum transaction request failed or was rejected.');
}
}
</script>
<center>
<input type="button" class="button" value="From Original Site" onclick="openBingAndPromptTransaction()">
</center>
</body>
</html>