This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
arcTransitionGuide.html
511 lines (471 loc) · 20.9 KB
/
arcTransitionGuide.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>AlgoSigner ARC Transition Guide</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@creativebulma/[email protected]/dist/bulma-tooltip.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/tomorrow.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<link rel="stylesheet" type="text/css" href="./assets/style.css">
</head>
<body>
<div class="container">
<h1 class="title pt-3">
`window.AlgoSigner` to `window.algorand` Transition Guide
</h1>
<p>
Presently, both the <b>AlgoSigner</b> object and the <b>algorand</b> object coexist and work side-by-side, but there's plans to deprecate the <b>AlgoSigner</b> object in future versions of AlgoSigner.
</p>
</div>
<hr/>
<!-- WINDOW OBJECT -->
<div class="container">
<h1 class="title">
AlgoSigner API
</h1>
<p class="subtitle">
<span class="icon has-text-warning">
<i class="fas fa-exclamation-triangle"></i>
</span>
There is a change in the way to access AlgoSigner methods
</p>
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth" id="algosigner-object">window.AlgoSigner</button>
<pre><code class="js">
if (typeof <b>AlgoSigner</b> !== 'undefined') {
console.log('AlgoSigner object is available.');
} else {
console.log('AlgoSigner object was not found.');
}
</code></pre>
</div>
<div class="column" style="overflow: visible;">
<button
data-tooltip="Click me to run this block of code!"
class="button is-primary is-fullwidth has-tooltip-arrow has-tooltip-active"
id="algorand-object">
window.algorand
</button>
<pre><code class="js">
if (typeof <b>algorand</b> !== 'undefined') {
console.log('algorand object is available.');
} else {
console.log('algorand object was not found.');
}
</code></pre>
</div>
</div>
<pre class="mt-2"><code class="js" id="object-code">code snippet output</code></pre>
</div>
<!-- /WINDOW OBJECT -->
<!-- SDKSETUP -->
<div class="container">
<hr />
<h1 class="title">
Client Setup & Transaction Parameters Fecthing
</h1>
<p class="subtitle">
<span class="icon has-text-success">
<i class="fas fa-check-circle"></i>
</span>
The algosdk client setup is not effected by the transition
</p>
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth" id="sdk-client">Setup SDK client</button>
<pre><code class="js">
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
algodClient = new algosdk.Algodv2(token, algodServer, '');
algodClient.getTransactionParams().do()
.then(d => txnParams = d)
.catch(e => console.error(e));
</code></pre>
</div>
<div class="column">
<button class="button is-primary is-fullwidth" id="algorand-client">Setup SDK client</button>
<pre><code class="js">
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
algodClient = new algosdk.Algodv2(token, algodServer, '');
algodClient.getTransactionParams().do()
.then(d => txnParams = d)
.catch(e => console.error(e));
</code></pre>
</div>
</div>
<pre class="mt-2"><code class="JSON" id="client-code">code snippet output</code></pre>
</div>
<!-- /SDKSETUP -->
<!-- ENABLE -->
<div class="container">
<hr />
<h1 class="title">
Connect / Accounts
</h1>
<p class="subtitle">
<span class="icon has-text-warning">
<i class="fas fa-exclamation-triangle"></i>
</span>
There is a change in the way you connect to AlgoSigner and retrieve accounts
</p>
<p>Additional documentation can be found <a href="https://github.com/PureStake/algosigner/blob/develop/docs/dApp-integration.md#algorandenableenableopts-enableopts">here</a></p>
</br>
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth" id="algosigner-connect">AlgoSigner.connect()</button>
<pre><code class="js">
<b>AlgoSigner</b>.connect()
.catch(e => console.error(e));
<b>AlgoSigner</b>.accounts({ ledger: 'TestNet' })
.then(d => accounts = d)
.catch(e => console.error(e));
</code></pre>
</div>
<div class="column">
<button class="button is-primary is-fullwidth" id="algorand-enable">algorand.enable()</button>
<pre><code class="js">
<b>algorand</b>.enable({
genesisID: 'testnet-v1.0',
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
})
.then(d => accounts = d.accounts)
.catch(e => console.error(e));
</code></pre>
</div>
</div>
<pre class="mt-2"><code class="JSON" id="accounts-code">code snippet output</code></pre>
</div>
<!-- /ENABLE -->
<!-- SIGN -->
<div class="container">
<hr />
<h1 class="title">
Sign Transactions
</h1>
<p class="subtitle">
<span class="icon has-text-warning">
<i class="fas fa-exclamation-triangle"></i>
</span>
There's a difference in the method names, as well as the method response when signing transactions
</p>
<p>
<b>Method name:</b> The signing method changes from <code>AlgoSigner.<b>signTxn</b></code> to <code>algorand.<b>signTxns</b></code>.
</p>
<p>
<b>Method response:</b> The returned signed blobs structure changes from <code>[{ txID, blob }, { txID, blob }, ...]</code> to <code>[ blob, blob, ... ]</code>.
</p>
<br />
<div >
<div class="field">
<div class="control has-icons-left">
<div class="select is-fullwidth">
<select id="from">
<option>Request accounts first</option>
</select>
</div>
<div class="icon is-small is-left">
<i class="fas fa-wallet"></i>
</div>
</div>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" id="to" placeholder="To">
<span class="icon is-small is-left">
<i class="fas fa-share"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" id="amount" placeholder="µAlgos">
<span class="icon is-small is-left">
<i class="fas fa-coins"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" id="note" placeholder="Note">
<span class="icon is-small is-left">
<i class="fas fa-sticky-note"></i>
</span>
</p>
</div>
</div>
<br />
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth" id="algosigner-sign">AlgoSigner.signTxn()</button>
<pre><code class="js">
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: <b>AlgoSigner</b>.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = <b>AlgoSigner</b>.encoding.msgpackToBase64(txn.toByte());
<b>AlgoSigner.signTxn</b>([{txn: b64EncodedTxn}])
.then(d => signedTxs = d)
.catch(e => console.error(e));
</code></pre>
</div>
<div class="column">
<button class="button is-primary is-fullwidth" id="algorand-sign">algorand.signTxns()</button>
<pre><code class="js">
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: <b>algorand</b>.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = <b>algorand</b>.encoding.msgpackToBase64(txn.toByte());
<b>algorand.signTxns</b>([{txn: b64EncodedTxn}])
.then(d => signedTxs = d)
.catch(e => console.error(e));
</code></pre>
</div>
</div>
<pre class="mt-2"><code class="JSON" id="sign-code">code snippet output</code></pre>
</div>
<!-- /SIGN -->
<!-- SEND-POST -->
<div class="container">
<hr />
<h1 class="title">
Send Signed Transactions
</h1>
<p class="subtitle">
<span class="icon has-text-warning">
<i class="fas fa-exclamation-triangle"></i>
</span>
There is a change in the way signed transactions are sent to the network.
</p>
<p>
<b>Method name:</b> The method used changes from <code>AlgoSigner.<b>send</b></code> to <code>algorand.<b>postTxns</b></code>.
</p>
<p>
<b>Method parameters:</b> <code>algorand.postTxns</code> receives an array of signed transactions blobs instead of a single blob. The network is determined by the one selected during the <code>algorand.enable()</code> step.
</p>
<p>
<b>Method response:</b> similarly, <code>algorand.postTxns</code> returned object contains an array of txIDs instead of a single ID. The property inside the returned object name changes from <code>{ txId }</code> to <code>{ txIDs }</code>.
</p>
<p>
An additional method for signing and posting transactions with a single call is provided in the <code>algorand</code> object. Additional information can be found in the documentation <a href="https://github.com/PureStake/algosigner/blob/develop/docs/dApp-integration.md#algorandsignandposttxnstxnobjects-txnobject--txnobject">here</a>.
</p>
<br />
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth" id="algosigner-send">AlgoSigner.send()</button>
<pre><code class="js">
<b>AlgoSigner.send</b>({
ledger: 'TestNet',
tx: signedTxs[0].blob
})
.then(d => sendResponse = d)
.catch(e => console.error(e));
</code></pre>
</div>
<div class="column">
<button class="button is-primary is-fullwidth" id="algorand-post">algorand.postTxns()</button>
<pre><code class="js">
<b>algorand.postTxns</b>(signedTxs)
.then(d => sendResponse = d)
.catch(e => console.error(e));
</code></pre>
</div>
</div>
<pre class="mt-2"><code class="JSON" id="send-code">code snippet output</code></pre>
</div>
<!-- /SEND-POST -->
<footer class="footer">
<div class="content has-text-centered">
by <a target="_blank" rel="noopener noreferrer" href="https://purestake.com">
<img src="assets/ps-logo.png" height="28px">
</a>
</div>
</footer>
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script>
hljs.initHighlightingOnLoad();
let txnParams;
let signedTx;
let signedTxs;
let tx;
let algodClient;
// WINDOW OBJECT
document.getElementById('algosigner-object').addEventListener('click', () =>{
const responseElem = document.getElementById('object-code');
if (typeof window.AlgoSigner !== 'undefined') {
responseElem.innerHTML = 'AlgoSigner object is available.';
} else {
responseElem.innerHTML = 'AlgoSigner object was not found.';
}
});
document.getElementById('algorand-object').addEventListener('click', () =>{
const responseElem = document.getElementById('object-code');
if (typeof window.algorand !== 'undefined') {
responseElem.innerHTML = 'algorand object is available.';
} else {
responseElem.innerHTML = 'algorand object was not found.';
}
});
// CLIENT SETUP
function sdkSetup() {
let sdkSetupCodeElem = document.getElementById('client-code');
const server = 'https://testnet-algorand.api.purestake.io/ps2';
const token = { 'X-API-Key': 'B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab' };
algodClient = new algosdk.Algodv2(token, server, '');
algodClient.getTransactionParams().do()
.then(d => {
txnParams = d;
sdkSetupCodeElem.innerHTML = JSON.stringify(txnParams, null, 2);
})
.catch(e => sdkSetupCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(sdkSetupCodeElem));
}
document.getElementById('sdk-client').addEventListener('click', sdkSetup);
document.getElementById('algorand-client').addEventListener('click', sdkSetup);
// CONNECT / ENABLE
document.getElementById('algosigner-connect').addEventListener('click', async () =>{
await AlgoSigner.connect();
let accountsCodeElem = document.getElementById('accounts-code');
AlgoSigner.accounts({ ledger: 'TestNet' })
.then(d => {
accountsCodeElem.innerHTML = JSON.stringify(d, null, 2);
// Append accounts to account select
let select = document.getElementById('from');
select.textContent = '';
for (var i = d.length - 1; i >= 0; i--) {
let option = document.createElement('option');
option.text = d[i].address;
option.value = d[i].address;
select.appendChild(option);
}
})
.catch(e => accountsCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(accountsCodeElem));
});
document.getElementById('algorand-enable').addEventListener('click', async () =>{
let accountsCodeElem = document.getElementById('accounts-code');
algorand.enable({
genesisID: 'testnet-v1.0',
})
.then(d => {
accountsCodeElem.innerHTML = JSON.stringify(d, null, 2);
// Append accounts to account select
let select = document.getElementById('from');
select.textContent = '';
for (const address of d['accounts']) {
let option = document.createElement('option');
option.text = address;
option.value = address;
select.appendChild(option);
}
})
.catch(e => accountsCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(accountsCodeElem));
});
// SIGN TXNS
document.getElementById('algosigner-sign').addEventListener('click', async () => {
let signCodeElem = document.getElementById('sign-code');
if (!algodClient || !txnParams) {
signCodeElem.innerHTML = 'Setup SDK and retrieve parameters before signing.';
return;
}
if (!document.getElementById('from').value
|| !document.getElementById('to').value
|| !document.getElementById('amount').value) {
signCodeElem.innerHTML = 'Initialize values above for from, to, and amount before signing.';
return;
}
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: AlgoSigner.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = AlgoSigner.encoding.msgpackToBase64(txn.toByte());
AlgoSigner.signTxn([{txn: b64EncodedTxn}])
.then(d => {
signedTxs = d;
signCodeElem.innerHTML = JSON.stringify(d, null, 2);
})
.catch(e => signCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(signCodeElem));
});
document.getElementById('algorand-sign').addEventListener('click', async () => {
let signCodeElem = document.getElementById('sign-code');
if (!algodClient || !txnParams) {
signCodeElem.innerHTML = 'Setup SDK and retrieve parameters before signing.';
return;
}
if (!document.getElementById('from').value
|| !document.getElementById('to').value
|| !document.getElementById('amount').value) {
signCodeElem.innerHTML = 'Initialize values above for from, to, and amount before signing.';
return;
}
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: document.getElementById('from').value,
to: document.getElementById('to').value,
amount: +document.getElementById('amount').value,
note: algorand.encoding.stringToByteArray(document.getElementById('note').value),
suggestedParams: {...txnParams}
});
// Use the AlgoSigner encoding library to make the transactions base64
let b64EncodedTxn = algorand.encoding.msgpackToBase64(txn.toByte());
algorand.signTxns([{txn: b64EncodedTxn}])
.then(d => {
signedTxs = d;
signCodeElem.innerHTML = JSON.stringify(d, null, 2);
})
.catch(e => signCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(signCodeElem));
});
// POST TXNS
document.getElementById('algosigner-send').addEventListener('click', async () => {
let sendCodeElem = document.getElementById('send-code');
if (!signedTxs || !signedTxs[0]) {
sendCodeElem.innerHTML = 'Complete transaction signing before attempting to send.';
return;
}
AlgoSigner.send({
ledger: 'TestNet',
tx: signedTxs[0].blob
})
.then(d => {
sendCodeElem.innerHTML = JSON.stringify(d, null, 2);
sendResponse = d;
})
.catch(e => sendCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(sendCodeElem));
});
document.getElementById('algorand-post').addEventListener('click', async () => {
let sendCodeElem = document.getElementById('send-code');
if (!signedTxs) {
sendCodeElem.innerHTML = 'Complete transaction signing before attempting to send.';
return;
}
// Sending first transaction only for demo purposes
algorand.postTxns(signedTxs)
.then(d => {
sendCodeElem.innerHTML = JSON.stringify(d, null, 2);
sendResponse = d;
})
.catch(e => sendCodeElem.innerHTML = JSON.stringify(e, null, 2))
.finally(() => hljs.highlightBlock(sendCodeElem));
});
</script>
<script src="https://unpkg.com/[email protected]"></script>
</body>
</html>