-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsac15.html
More file actions
51 lines (41 loc) · 1.71 KB
/
sac15.html
File metadata and controls
51 lines (41 loc) · 1.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Solana Transaction with Phantom</title>
</head>
<body>
<button id="solana-button">Send SOL with Phantom</button>
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
<script>
const connectButton = document.getElementById('solana-button');
connectButton.addEventListener('click', async () => {
try {
const provider = await window.solana.connect();
// Replace with your recipient address and lamport amount
const toPubkey = new solanaWeb3.PublicKey('3G8FH9vRaBWQDCjrbbQ9ioa3Bju9iPsakCmpcRgmpoJc');
const lamports = 100000; // 0.1 SOL
const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('devnet'));
const transaction = new solanaWeb3.Transaction().add(
solanaWeb3.SystemProgram.transfer({
fromPubkey: provider.publicKey,
toPubkey,
lamports,
})
);
const { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = provider.publicKey;
const signedTransaction = await provider.signTransaction(transaction);
const txid = await connection.sendRawTransaction(signedTransaction.serialize());
console.log('Transaction Sent:', txid);
// Optionally, wait for confirmation
await connection.confirmTransaction(txid);
console.log('Transaction Confirmed');
} catch (err) {
console.error(err);
}
});
</script>
</body>
</html>