Task: Read a Quote, Write a Quote (using JavaScript)

#1

Task: Read a Quote, Write a Quote (using JavaScript)

In this task, you can choose to either write a string to the blockchain or read a string from the blockchain (or both!) using the JS SDK. You can perform this task with a Node.js application or in a Web Application. Documentation is available on reading and writing strings to the note field using the JS SDK here.

Task Instructions

As a writer:

  1. Using the JS SDK, create a Node.js or Web application that creates an account.
  2. Use the dispenser to add tokens to the account.
  3. Using the JS SDK, create a transaction that has a notefield property set with your favorite quote (or your own words of wisdom)! Keep it clean!
  4. Set the “to” transaction property to our account: NJY27OQ2ZXK6OWBN44LE4K43TA2AV3DPILPYTHAJAMKIVZDWTEJKZJKO4A
  5. Submit the transaction and enter the transaction ID as a reply to this task thread.
  6. Wait for a reader to reveal your quote!

As a reader:

  1. Scope out a writer’s transaction that was posted on this community thread and not yet revealed.
  2. Make sure your node is set to archival if the transaction you are locating will require you to look more than 300 blocks in the past.
  3. Using the JS SDK, create a Node.js or Web application
  4. Locate the transaction and read the note field.
  5. Post the revealed quote in reply to the writer!

Send us feedback! We would love to hear what you liked about the JS SDK functionalities and/or what could be improved. Reply to this thread on Community or email us at testnet-team@algorand.com.

Prerequisites

  1. Make sure you have completed all the steps here to get your node up and running.
  2. Check that you are running the latest version.
  3. If you are a reader and want to look for historical transactions past 300 blocks, make sure you set your node’s archival value to True.

Hint

The JavaScript SDK repository has a sample Web Application showcasing various methods using the JS SDK.

Why This Task Matters

Within the notefield you can post any arbitrary data structure (up to 1KB in size) to the blockchain, which gives you the ability to create and templatize your own transaction types. In this task, you can familiarize yourself with this core functionality (i.e. reading and writing to the notefield). We also hope you will share feedback on the documentation and feature set so far.

Have Questions?

Post them here!

You will earn the SDK Developer badge for completing this task:

2 Likes
Testnet Resources
#2

tx-EXQVLGRRARXG5KG5EBZVVJD3GK2GI5S4PET33OKN36S42KD65ZRQ

#3

tx-B2NLM2JU2CXTTNOKJZJDIT4AD4EMWQOUPMRH44HAJDKCJ7OSR7SA

1 Like
#4

Just in case you are running another service on port 8080, like I was doing (and therefore was getting strange errors from the APIs). You can change the algorand endpoint address to run on another port. In my case I choose port 8090, so I changed the config.json to look like the following, and I restarted the algorand service

1 Like
#5

tx-MQSJUAI2565M35YT4CAGFOS5M7XXWVAA5WDURBAHZ4G7EKR766RQ

1 Like
#6

Kasper posted:

Transactions By Address {
“By”: “Jean Baudrillard”,
“Quote”: “The simulacrum is never that which conceals the truth it is the truth which conceals that there is none. The simulacrum is true”
}

2 Likes
#7

Liz Posted:

‘Imagination is more important than knowledge.’ - Albert Einstein

#8

tx-MXMPXJHWOMOTYMRUNW6VIAHV5GUGOC74M5PY4OZ5MM5ZMLDTPJGA

#9

Hi @liz , i tried install algosdk but i got this instead:

npm install algosdk
/
└─┬ algosdk@1.0.5
└── msgpack-lite@0.1.26 (git+https://github.com/algorand/msgpack-lite.git#549d9211c47863da5ad1b69276e363617c9a5c78)

npm WARN enoent ENOENT: no such file or directory, open ‘/package.json’
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data

does this mean success? or am i missing something? I cant find algod token

#10

You need to run npm install algosdk in an existing npm-initialized directory (where package.json exists). Typically you install the SDK modules into an existing project. But in general, you need to have run npm init first.

#11

Tx
MXMPXJHWOMOTYMRUNW6VIAHV5GUGOC74M5PY4OZ5MM5ZMLDTPJGA

Decoded note:
“Waste no more time arguing about what a good man should be. Be one. Marcus Aurelius”

#12

Some feedback/questions from doing this exercise:

  1. My copy of the JS SDK had to be updated first before being able to complete everything.

  2. Against the node I’m using, the transactionInformation method seems to have a time window for how far back it searches and then it returns txn not found. The node is archival and I tested retrieving older blocks to validate.

Is there a configuration setting for this? In the REST path docs, this is mentioned “This call scans up to config.Protocol.MaxTxnLife blocks in the past.

#13
@marmar 
{
    "code": "who='World';print (f'Hello {who}')",
    "description": "Sample hello world code in python",
    "language": "python3",
    "platform": "any",
    "shebang": "#!/usr/bin/env python"
}
#14

Thanks to @David, I have successfully install algosdk. Now I am stuck at algod token. Where can I find it? Do i need to generate it first?

Thanks

#15

There is a file called algod.token in your ~./node/data directory

#16

Tim,

The transactionInformation call currently only looks back 1k blocks. I need to update the docs on this. We are looking at ways to better support historic reads.

Jason

#17

What will cause that algod.token to update/change - service restarts, ledger updates, new software versions?

#18

Good question. @JasonW @David?

#19

Once the algod.token file (and kmd.token file) is created, we will not automatically delete it or overwrite it. You can manually delete it or replace it / modify it.

1 Like
#20

Thanks for the tip MarMar. By default, we try to use localhost:8080 and fallback to ‘any’ if it’s unavailable. But clearly if we take it before your other service tries to use it, that will cause issues with your other service.