CVNSS commited on
Commit
92f19e8
·
verified ·
1 Parent(s): 6815bf3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +83 -17
index.html CHANGED
@@ -1,19 +1,85 @@
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>
3
+ <head>
4
+ <title>Giao dịch Solana + Lưu Google Sheet</title>
5
+ </head>
6
+ <body>
7
+ <h2>Gửi giao dịch Solana + Memo</h2>
8
+ <form id="sendForm">
9
+ Địa chỉ nhận SOL:<br>
10
+ <input type="text" id="to" size="45" required><br>
11
+ Số lượng SOL:<br>
12
+ <input type="number" id="amount" step="0.0001" required><br>
13
+ Nội dung Memo:<br>
14
+ <input type="text" id="memo" size="45"><br>
15
+ <button type="submit">Gửi giao dịch</button>
16
+ </form>
17
+ <div id="result"></div>
18
+
19
+ <script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
20
+ <script>
21
+ // Kết nối Phantom
22
+ const provider = window.solana;
23
+
24
+ document.getElementById('sendForm').onsubmit = async function(e) {
25
+ e.preventDefault();
26
+ const to = document.getElementById('to').value.trim();
27
+ const amount = parseFloat(document.getElementById('amount').value);
28
+ const memo = document.getElementById('memo').value.trim();
29
+
30
+ if (!provider || !provider.isPhantom) {
31
+ alert('Cần cài Phantom wallet!');
32
+ return;
33
+ }
34
+ await provider.connect();
35
+
36
+ const connection = new solanaWeb3.Connection('https://api.devnet.solana.com');
37
+ const fromPubkey = provider.publicKey;
38
+ const toPubkey = new solanaWeb3.PublicKey(to);
39
+
40
+ // Tạo instructions: transfer + memo
41
+ const tx = new solanaWeb3.Transaction().add(
42
+ solanaWeb3.SystemProgram.transfer({
43
+ fromPubkey,
44
+ toPubkey,
45
+ lamports: amount * solanaWeb3.LAMPORTS_PER_SOL
46
+ })
47
+ );
48
+ if (memo) {
49
+ tx.add(
50
+ new solanaWeb3.TransactionInstruction({
51
+ keys: [],
52
+ programId: new solanaWeb3.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
53
+ data: Buffer.from(memo)
54
+ })
55
+ );
56
+ }
57
+ tx.feePayer = fromPubkey;
58
+ tx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
59
+
60
+ // Ký và gửi giao dịch
61
+ const signed = await provider.signTransaction(tx);
62
+ const signature = await connection.sendRawTransaction(signed.serialize());
63
+ document.getElementById('result').innerText = "Đã gửi! Signature: " + signature;
64
+
65
+ // Gửi dữ liệu lên Google Sheet qua Apps Script API
66
+ const sheetApiUrl = 'https://script.google.com/macros/s/AKfycby2JmDEj_yO17IuUHraNZn4kSqQBYLYrM2MRE3KUNZZlsiIkC8iPA2xh-18ip-Xbtr0sw/exec'; // thay bằng URL Apps Script bạn vừa deploy
67
+ const payload = {
68
+ signature: signature,
69
+ from: fromPubkey.toString(),
70
+ to: to,
71
+ amount: amount,
72
+ memo: memo,
73
+ time: new Date().toISOString()
74
+ };
75
+ fetch(sheetApiUrl, {
76
+ method: 'POST',
77
+ body: JSON.stringify(payload),
78
+ headers: {'Content-Type': 'application/json'}
79
+ });
80
+
81
+ alert("Giao dịch đã gửi! Kiểm tra trạng thái tại Solscan.io (Devnet) và Google Sheet!");
82
+ }
83
+ </script>
84
+ </body>
85
  </html>