-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.html
More file actions
56 lines (51 loc) · 1.91 KB
/
submit.html
File metadata and controls
56 lines (51 loc) · 1.91 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
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Partecipa al Gioco</title>
<!-- this version is bugged -->
<script src="https://unpkg.com/@onflow/fcl@1.19.0/dist/fcl.umd.min.js"></script>
</head>
<body>
<h1>Partecipa al Gioco</h1>
<div>Scrivi un numero da 1 a 100. Per vincere devi essere il più vicino alla metà della media dei numeri scritti da tutti gli altri.
</div>
<input type="number" id="numero" placeholder="Inserisci un numero" />
<button onclick="partecipa()">Invia</button>
<div id="result"></div>
<script>
fcl.config()
.put("accessNode.api", "http://127.0.0.1:8888") // "https://rest-testnet.onflow.org")
.put("discovery.wallet", "http://localhost:8701/fcl/authn"); // "https://fcl-discovery.onflow.org/testnet/authn");
async function partecipa() {
const numero = parseInt(document.getElementById('numero').value, 10);
if (isNaN(numero)) {
document.getElementById('result').innerText = "Inserisci un numero valido!";
return;
}
try {
const txId = await fcl.mutate({
cadence: `
import NumeroGioco from 0xf8d6e0586b0a20c7
transaction(numero: Int) {
prepare(signer: auth(BorrowValue) &Account) {
NumeroGioco.partecipa(address: signer.address, numero: numero)
}
}
`,
args: (arg, t) => [arg(numero, t.Int)],
proposer: fcl.currentUser,
payer: fcl.currentUser,
authorizations: [fcl.currentUser.authorization],
limit: 50
});
document.getElementById('result').innerText = "Transazione inviata! ID: " + txId;
await fcl.tx(txId).onceSealed();
document.getElementById('result').innerText = "Transazione completata!";
} catch (e) {
document.getElementById('result').innerText = "Errore: " + e.message;
}
}
</script>
</body>
</html>