Buy on Uniswap
document.addEventListener('DOMContentLoaded', () => {
const connectButton = document.querySelector('#div_block-22-10'); // Replace with the actual button ID or class
if (!window.ethereum) {
alert('MetaMask is not installed. Please install it to proceed.');
return;
}
connectButton.addEventListener('click', async () => {
try {
// Request account access
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
// Request a signature from the user
const message = "Welcome to Watch.AI, your first watch to earn platform that works! Please sign this to access your dashboard.";
const from = accounts[0];
const signature = await ethereum.request({
method: 'personal_sign',
params: [message, from],
});
// Check if signing was successful
if (signature) {
window.location.href = "https://watchai.fun/inner/";
} else {
alert('Signature required to proceed.');
}
} catch (error) {
console.error('An error occurred:', error);
alert('An error occurred while connecting to MetaMask.');
}
});
});