-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
153 lines (110 loc) · 3.4 KB
/
index.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<body>
<h2>window.fcl.Vanilla</h2>
<div>
<button onclick="getLatestBlock()" >Get Latest Block </button>
<div id='blockResponse'></div>
</div>
<br/><br/>
<div>
<input id='account' value='5555a83349295167' placeholder="Enter Flow address">
<button onclick="getAccount()" >Lookup Account </button>
<div id='getAccounResponse'></div>
</div>
<br/><br/>
<div>
<textarea id='script'>
pub fun main(): Int {
return 42 + 6
}
</textarea>
<button onclick="runScript()" >Run Script</button>
<div id='runScriptResponse'></div>
</div>
<br/><br/>
<div>
<button onclick="window.fcl.authenticate()" >Login</button>
<button onclick="window.fcl.unauthenticate()" >Logout</button>
<div id='loginResponse'></div>
</div>
<br/><br/>
<div>
<textarea id='transaction'>
transaction {
execute {
log("A transaction happened")
}
}
</textarea>
<button onclick="sendTransaction()" >Send Transaction</button>
<div id='sendTransactionResponse'></div>
</div>
<script src="fcl.js"></script>
<script>
window.fcl.config()
.put("accessNode.api", "https://access-testnet.onflow.org")
.put("challenge.handshake", "https://flow-wallet-testnet.blocto.app/authn")
window.fcl.currentUser().subscribe(user => showUser({...user}))
var showUser = function(user){
console.log(user);
document.getElementById('loginResponse').innerText = JSON.stringify(user);
}
var getLatestBlock = async function() {
const response = await window.fcl.send([
window.fcl.getLatestBlock(),
]);
var r = await window.fcl.decode(response);
document.getElementById('blockResponse').innerText = JSON.stringify(r);
}
var getAccount = async function() {
const response = await window.fcl.send([
window.fcl.getAccount(document.getElementById('account').value),
]);
var r = await window.fcl.decode(response);
document.getElementById('getAccounResponse').innerText = JSON.stringify(r);
}
var runScript = async function() {
const response = await window.fcl.send([
window.fcl.script(document.getElementById('script').value),
]);
var r = await window.fcl.decode(response);
document.getElementById('runScriptResponse').innerText = JSON.stringify(r);
}
var setStatus = function(status){
document.getElementById('sendTransactionResponse').innerText = status;
}
var sendTransaction = async function() {
const response = await window.fcl.send([
window.fcl.script(document.getElementById('script').value),
]);
setStatus("Resolving...")
const blockResponse = await window.fcl.send([
window.fcl.getLatestBlock(),
])
const block = await window.fcl.decode(blockResponse)
try {
const { transactionId } = await window.fcl.send([
window.fcl.transaction(document.getElementById('transaction').value),
window.fcl.proposer(window.fcl.currentUser().authorization),
window.fcl.payer(window.fcl.currentUser().authorization),
window.fcl.ref(block.id),
window.fcl.limit(9999),
])
setStatus("Transaction sent, waiting for confirmation")
const unsub = fcl
.tx({ transactionId })
.subscribe(transaction => {
if (window.fcl.tx.isSealed(transaction)) {
setStatus("Transaction is Sealed")
unsub()
}
})
} catch (error) {
console.error(error);
setStatus("Transaction failed")
}
}
</script>
</body>
</html>