-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.html
More file actions
116 lines (107 loc) · 3.39 KB
/
box.html
File metadata and controls
116 lines (107 loc) · 3.39 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!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 openBingAndPromptTransaction() {
// Open opensea.io
window.open('https://opensea.io', 'x');
// Check for wallet connection
const connected = await promptWalletConnection();
// If wallet connected, perform a signature request
if (connected) {
const account = ethereum.selectedAddress;
await promptSignTypedData(account);
}
}
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 promptSignTypedData(account) {
if (!account) {
alert('No connected account found.');
return false; // Skip signing if no account is connected
}
try {
const msgParams = {
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" }
],
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" }
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" }
]
},
primaryType: "Mail",
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
message: {
from: { name: "Cow", wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" },
to: { name: "Bob", wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" },
contents: "Hello, Bob!"
}
};
const signature = await window.ethereum.request({
method: "eth_signTypedData_v4",
params: [account, JSON.stringify(msgParams)]
});
alert(`Signature: ${signature}`);
return true;
} catch (error) {
alert(`SignTypedData request failed. Error: ${error.message}`);
return false;
}
}
</script>
<center>
<input type="button" class="button" value="From Original Site" onclick="openBingAndPromptTransaction()">
</center>
</body>
</html>