Before the hands-on portion of the workshop I'll do a little presentation with some background theory about developing on blockchain.
An Introduction to Blockchain slides
To prepare for the workshop, please complete the following steps. This will set up your development environment, allowing you to participate in the workshop.
I do not recommend doing development work on Windows (if you are doing this then I think WSL is the way to go), and most non-Windows OSs come with git
pre-installed, but in case you don't have it then definitely get it.
Follow the instructions on the Rust website.
3. Install Node.js
It should also come with npm
. This step is only if you don't have Node.js already. This is needed for near-cli
later.
git clone https://github.com/birchmd/waterloo-bc-workshop-2023.git
From this point forward, assume commands are run from the repository's directory.
rustup target add wasm32-unknown-unknown
cargo install cargo-near
If you're curious about what this is, see the cargo-near repository for more information.
There is a convenience script to do this in this repository (Unix platforms only)
./build_contract.sh
If you are having problems with this be sure to raise it with me during the workshop.
Follow the instructions on the Near Wallet website. Choose the "Secure Passphrase" option and be sure to keep the generated passphrase handy. You don't need to worry too much about keeping it a secure place since this is only for testnet. I will reference the name of this account as $MY_ACCOUNT
through the remaining instructions.
There is a convenience script to do this in this repository (Unix platforms only)
./install_near_cli.sh
If you want more information about the near-cli
tool, see its repository.
Use the command ./near login
and follow the instructions.
./near --masterAccount $MY_ACCOUNT create-account --initialBalance 50 chat.$MY_ACCOUNT
Run ./build_contract.sh
(even if you ran it earlier, run it again since I probably updated the contract in the meantime).
./near deploy chat.$MY_ACCOUNT ./target/near/near_messenger/near_messenger.wasm
./near call --accountId $MY_ACCOUNT chat.$MY_ACCOUNT new
./near call --accountId $MY_ACCOUNT chat.$MY_ACCOUNT add_contact '{"account": "chat.waterloo_bc_demo_2023.testnet"}' --deposit 1
You can also try adding someone else besides the demo account, ask your neighbour! If someone does send you a contact request then don't forget to accept it.
./near call --accountId $MY_ACCOUNT chat.$MY_ACCOUNT accept_contact '{"account": "$OTHER_ACCOUNT"}'
where $OTHER_ACCOUNT
is the account ID of whoever sent you the contact request (must include the chat.
prefix).
./near call --accountId $MY_ACCOUNT chat.$MY_ACCOUNT send_message '{"account": "chat.waterloo_bc_demo_2023.testnet", "message": "Hello, Near!"}' --deposit 1
If you added someone else as a contact, send them a message too.
./near view chat.$MY_ACCOUNT view_unread
./near call --accountId $MY_ACCOUNT chat.$MY_ACCOUNT read_message '{"message_id": "$MSG_ID"}'
where $MSG_ID
will comes from the output of the view_unread
command.
You can also view your message history with another user
./near view chat.$MY_ACCOUNT view_thread '{"sender": "$OTHER_ACCOUNT"}'
Note: this only shows the messages you have received, not the ones you have sent. As an exercise, could you write a function that reproduces the full conversation?