From 8cf14f97fc8e14d4e8bcca6a2e200f750396b0c8 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Tue, 17 Nov 2020 13:42:18 -0300 Subject: [PATCH] Add Examples for Assets Transfer and Close with send Remainder --- asset-close.html | 564 +++++++++++++++++++++++++++++++++++++++++++ asset-create.html | 2 + asset-optin.html | 2 + asset-transfer.html | 570 ++++++++++++++++++++++++++++++++++++++++++++ index.html | 2 + payment.html | 2 + 6 files changed, 1142 insertions(+) create mode 100644 asset-close.html create mode 100644 asset-transfer.html diff --git a/asset-close.html b/asset-close.html new file mode 100644 index 0000000..5317074 --- /dev/null +++ b/asset-close.html @@ -0,0 +1,564 @@ + + + + + + AlgoSigner dApp | Asset Opt-in + + + + + + + + + + + +
+
+

+ Connect + + + + + See code on GitHub + +

+

+ Connect to AlgoSigner +

+ +
+
+ +
response
+
+
+
AlgoSigner.connect()
+.then((d) => {
+  ...
+})
+.catch((e) => {
+  console.error(e);
+});
+
+
+
+
+ + + +
+
+

+ Get TestNet Accounts + + + + + See code on GitHub + +

+

+ Gets the users TestNet accounts +

+ +
+
+ +
response
+
+
+
AlgoSigner.accounts({
+  ledger: 'TestNet'
+})
+.then((d) => {
+  accounts = d;
+})
+.catch((e) => {
+  console.error(e);
+});
+
+
+
+
+ + + +
+
+

+ Get Params + + + + + See code on GitHub + +

+

+ Query AlgoD to get TestNet suggested TX Params +

+ +
+
+ +
response
+
+
+
AlgoSigner.algod({
+  ledger: 'TestNet',
+  path: '/v2/transactions/params'
+})
+.then((d) => {
+  txParams = d;
+})
+.catch((e) => {
+  console.error(e);
+});
+
+
+
+
+ + + +
+
+

+ Get Assets from Indexer + + + + + See code on GitHub + +

+

+ Query Indexer to get TestNet assets +

+ +
+
+
+

+ + + + +

+
+
+

+ + + + +

+
+ +
response
+
+
+
const name = document.getElementById("name").value;
+const limit = document.getElementById("limit").value;
+
+AlgoSigner.indexer({
+  ledger: 'TestNet',
+  path: `/v2/assets?name=${name}&limit=${limit}`,
+})
+.then((d) => {
+  document.getElementById("assets-code").innerHTML = JSON.stringify(d);
+})
+.catch((e) => {
+  console.error(e);
+  document.getElementById("assets-code").innerHTML = JSON.stringify(e);
+});
+
+
+
+
+ + + +
+
+

+ Sign Asset Close Transaction + + + + + See code on GitHub + +

+

+ Ask the user to sign an asset close transaction using AlgoSigner's Sign method +

+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+

+ + + + +

+
+
+

+ + + + +

+
+ +
response
+
+
+
+            AlgoSigner.sign({
+            "from": document.getElementById("from").value,
+            "to": document.getElementById("to").value,
+            "assetIndex": +document.getElementById("asset").value,
+            "note": document.getElementById("note").value,
+            "amount": 0,
+            "type": "axfer",
+            "fee": txParams['min-fee'],
+            "firstRound": txParams['last-round'],
+            "lastRound": txParams['last-round'] + 1000,
+            "genesisID": txParams['genesis-id'],
+            "genesisHash": txParams['genesis-hash'],
+            "closeRemainderTo": document.getElementById("to").value,
+          })
+          .then((d) => {
+            signedTx = d;
+          })
+          .catch((e) => {
+            console.error(e);
+          });
+          
+
+
+
+
+ + + +
+
+

+ Send Signed Transaction + + + + + See code on GitHub + +

+

+ Send the previously signed transaction using AlgoSigner's Send method +

+ +
+
+ +
response
+
+
+
AlgoSigner.send({
+  ledger: 'TestNet',
+  tx: signedTx.blob
+})
+.then((d) => {
+  tx = d;
+})
+.catch((e) => {
+  console.error(e);
+});
+
+
+
+
+ + + +
+
+

+ Check pending transaction + + + + + See code on GitHub + +

+

+ Query the pending transaction endpoint to check the sent transaction status +

+ +
+
+ +
response
+
+
+
AlgoSigner.algod({
+  ledger: 'TestNet',
+  path: '/v2/transactions/pending/' + tx.txId
+})
+.then((d) => {
+  console.log(d);
+})
+.catch((e) => {
+  console.error(e);
+});
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/asset-create.html b/asset-create.html index 90c253c..c900f03 100644 --- a/asset-create.html +++ b/asset-create.html @@ -21,6 +21,8 @@ Payment Tx Asset Create Tx Asset Opt-in Tx + Asset Transfer Tx + Asset Close Tx