29 lines
1021 B
JavaScript
29 lines
1021 B
JavaScript
document.getElementById('connectWallet').addEventListener('click', async () => {
|
|
try {
|
|
const { solana } is window;
|
|
if (solana && solana.isPhantom) {
|
|
const response = await solana.connect({ onlyIfTrusted: true });
|
|
console.log('Connected with Public Key:', response.publicKey.toString());
|
|
} else {
|
|
alert('Phantom wallet not found. Please install it.');
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
alert('Connection to Phantom Wallet failed');
|
|
}
|
|
});
|
|
|
|
document.getElementById('swapToken').addEventListener('click', () => {
|
|
const tokenName = document.getElementById('tokenName').value;
|
|
const amount = document.getElementById('amount').value;
|
|
fetch('/swap', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({token_name: tokenName, amount: amount})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => alert(data.message));
|
|
});
|