CVNSS commited on
Commit
da3d4ce
·
verified ·
1 Parent(s): e541af9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +89 -18
index.html CHANGED
@@ -1,19 +1,90 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Solana IDM Demo</title>
6
+ <style>
7
+ body { font-family: Arial, sans-serif; padding: 20px; max-width: 500px; margin: auto; }
8
+ input, textarea, button { width: 100%; margin-top: 10px; padding: 8px; font-size: 16px; }
9
+ button { background-color: #4CAF50; color: white; border: none; cursor: pointer; }
10
+ button:hover { background-color: #45a049; }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <h2>🟣 Gửi Tin nhắn IDM qua Solana</h2>
15
+
16
+ <button onclick="connectWallet()">🔌 Kết nối ví Phantom</button>
17
+ <div id="wallet-address" style="margin-top:10px; font-weight: bold;"></div>
18
+
19
+ <input type="text" id="recipient" placeholder="🎯 Nhập địa chỉ ví người nhận">
20
+ <textarea id="message" rows="4" placeholder="💬 Nội dung tin nhắn (memo)"></textarea>
21
+ <button onclick="sendMemo()">📨 Gửi tin nhắn</button>
22
+
23
+ <div id="result" style="margin-top: 15px;"></div>
24
+
25
+ <script src="https://cdn.jsdelivr.net/npm/@solana/web3.js@1.77.2/lib/index.iife.min.js"></script>
26
+ <script>
27
+ let provider = null;
28
+
29
+ async function connectWallet() {
30
+ if ('solana' in window) {
31
+ provider = window.solana;
32
+ if (provider.isPhantom) {
33
+ try {
34
+ const resp = await provider.connect();
35
+ document.getElementById("wallet-address").innerText = "🪪 Đã kết nối: " + resp.publicKey.toString();
36
+ } catch (err) {
37
+ alert("Kết nối bị từ chối");
38
+ }
39
+ } else {
40
+ alert("Cài đặt ví Phantom trước nhé!");
41
+ }
42
+ }
43
+ }
44
+
45
+ async function sendMemo() {
46
+ const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('devnet'));
47
+ const recipient = document.getElementById("recipient").value.trim();
48
+ const message = document.getElementById("message").value.trim();
49
+
50
+ if (!provider || !provider.publicKey) {
51
+ alert("Bạn chưa kết nối ví Phantom!");
52
+ return;
53
+ }
54
+ if (!recipient || !message) {
55
+ alert("Vui lòng nhập đầy đủ địa chỉ và nội dung.");
56
+ return;
57
+ }
58
+
59
+ const transaction = new solanaWeb3.Transaction();
60
+
61
+ transaction.add(solanaWeb3.SystemProgram.transfer({
62
+ fromPubkey: provider.publicKey,
63
+ toPubkey: new solanaWeb3.PublicKey(recipient),
64
+ lamports: 0,
65
+ }));
66
+
67
+ transaction.add(new solanaWeb3.TransactionInstruction({
68
+ keys: [],
69
+ programId: new solanaWeb3.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
70
+ data: new TextEncoder().encode(message)
71
+ }));
72
+
73
+ transaction.feePayer = provider.publicKey;
74
+ const blockhashObj = await connection.getLatestBlockhash();
75
+ transaction.recentBlockhash = blockhashObj.blockhash;
76
+
77
+ try {
78
+ const signed = await provider.signTransaction(transaction);
79
+ const txid = await connection.sendRawTransaction(signed.serialize());
80
+ await connection.confirmTransaction(txid);
81
+ document.getElementById("result").innerHTML =
82
+ `✅ Đã gửi! <br>🧾 TxID: <a href="https://explorer.solana.com/tx/${txid}?cluster=devnet" target="_blank">${txid}</a>`;
83
+ } catch (err) {
84
+ console.error(err);
85
+ document.getElementById("result").innerText = "❌ Lỗi gửi giao dịch.";
86
+ }
87
+ }
88
+ </script>
89
+ </body>
90
  </html>