Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Latest commit

 

History

History
85 lines (70 loc) · 4.65 KB

README.md

File metadata and controls

85 lines (70 loc) · 4.65 KB

Algochat

Algochat is an app that uses Algorand blockchain to implement a public chat service.

It's not an official recommendation about making dapps mounted on Algorand, just a funny project to try the SDK and play around with the note field which can hold arbitrary byte data. Dirty, non-production ready, only a PoC!

Use

At the current moment, it works in the TestNet, so if you have an account with Algos you're ready to go.

$ go run main.go -h
Usage of main:
  -algodaddress string
        algod.net address (default "http://localhost:8080")
  -algodtoken string
        algod.token value
  -from string
        the addr of the wallet from which you will pay the txn fees
  -kmdaddress string
        kmd.net address (default "http://localhost:7833")
  -kmdtoken string
        kmd.token value
  -username string
        username to use in the chat (default "Guest")
  -wallet string
        the name of the wallet to use
  -walletpassword string
        the password of the wallet

For example:

$ go run main.go -wallet funnywallet -walletpassword funnypassword123 -from <from-addr-from-your-wallet> -algodtoken <algod.token> -kmdtoken <kmd.token> -username bobgorand

You'll see all the chat messages in the last 1000 blocks, and you can immediately start chatting.

Here a 20s demo: image

Check the logs to see what's happening.

Instructions

Prerequisites

  1. Install golang, sudo apt-get install golang
  2. Create go folder and set environment path variables
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF 

source ~/.bashrc

  1. Verify you have the GOPATH env correctly: echo $GOPATH
  2. Install git, sudo apt-get install git

Installation

  1. Inside the go folder, do: go get github.com/jsign/algochat
  2. Navigate inside the folder above, i.e. cd $GOPATH/src/github.com/jsign/algochat

Running the App

  1. Make sure you start kmd as it's not started by default on the node (goal kmd start)
  2. Launch the AlgoChat app

go run main.go -wallet -from your-account-address -algodaddress http://192.168.1.1:8080 -algodtoken your-algod-token -kmdtoken your-kmd-token -kmdaddress http://192.168.1.1:7833 -username Guest

  1. If using Windows and have an SSH client (e.g. Putty, SecureCRT), to display properly AlgoChat, you need in the appearance settings of the client to set character encoding to UTF-8

Thanks to nikandriko for elaborating the above step-by-step instructions.

In case you're having troubles with the algod.token or kmd.token, stop both the node and kmd, delete the .token files, and start them again goal node start (remember -d flag if you're not using the env variable config).

Random notes

  • Whenever a user sends a message to the chatroom it gets marshaled in the note field of the transaction.
  • Every transaction with the destination address KPLD4GPZYXST7S2ALYSAVRCBWYBCUQCN6T4N6HAYCHCP4GOV7KWJUGITBE is considered a message of the app.
  • Every message also shows the first 5 sringified characters of the address that sent the message as a prefix of the username.
  • The message is JSON encoded. Considering the note field size limitation, a more efficient encoding like protobufs would be more convenient.
  • The transaction corresponding to each message sends 0 algos to the chat address and uses the suggested fee from the SDK.
  • When you open the chat it will show the messages contained in the last 1000 blocks. Originally I wanted this to be parametrizable, but since the default node is non-archival it doesn't make much sense. 1000 blocks ~ 1-hour approx.
  • The SDK allows sending the transaction only asynchronously. After the transaction is submitted, the program scans the pending transactions until the sent transactionID is out of the pool, then considers the transaction confirmed (... not 100% true).
  • Ctrl+C will close the program immediately. The code doesn't worry about finishing goroutines gracefully.
  • Everything you see in the Algorand Chat window is exclusively confirmed on-chain. I intentionally avoided cheating showing new messages as soon as is submitted (before real confirmation). In a production chat service we'd intentionally do the opposite, display it right away with some UX signals (async).

Seems to be a good idea

  • Event notifications natively from the SDK, e.g, a new block has arrived.
  • Synchronous transaction sending or confirmation callbacks.
  • The SDK is a wrapper of the node REST API. Consider having gRPC endpoint on the node, might allow much powerful APIs? (use of streams for events, faster calls, less mem, etc).