DRW: Using Anchor to Speed Up Solana Development
Also updates about running an Althea validator and a Helium hotspot.
After two weeks of planned time away from the blog, it is time to post again. I waited until last minute, so here’s a brief overview of the most recent thing I learned about on Solana: Anchor.
Anchor Overview
Anchor is a program development framework for Solana built by the Serum team. It lets you leverage macros representing common coding patterns to speed up development. If you follow the right conventions, you’ll have working code, plus an IDL output that can be used to automagically generate Typescript bindings.
The Anchor documentation is really good. Below, I will copy some highlights directly from it.
Hello World
Even if you don’t know Anchor, or even Rust, it is pretty straight forward to understand that this block of code defines a program that returns Ok
.
Per the docs:
#[derive(Accounts)]
TheAccounts
derive macro marks a struct containing all the accounts that must be specified for a given instruction.
Building this code will then result in the output of the program represented as IDL
Fortunately, you don’t really have to understand much about the structure of the output to get started. The output can be directly imported into Anchor’s Typescript client and used to interact with the Solana program.
Anchor Installation
Once again, Anchor’s official installation instructions are excellent. The instructions below are specific to my environment (Mac with Yarn and NVM). I assume Rust and Solana are already installed but show how to check your versions.
# 1. Use most recent LTS version of node.
➜ nvm use --lts
➜ nvm version
v14.16.0
# 2. Check Rust version
➜ rustc --version
rustc 1.52.1 (9bc8c42bb 2021-05-09)
# 3. Check Solana version
➜ solana -V
solana-cli 1.6.1 (src:899f5796; feat:1880795386)
# 4. Install Mocha
➜ yarn global add mocha
# alternatively: npm install -g mocha
# 5. Install Anchor for Rust
# Releases: https://github.com/project-serum/anchor/tags
➜ cargo install \
--git https://github.com/project-serum/anchor \
--tag v0.9.0 anchor-cli \
--locked
# 6. Install Anchor for JS
➜ yarn global add @project-serum/anchor
Updates on running an Althea validator
I had successfully setup an Althea validator as part of their testnet for about a week. The process requires you to run both Althea/Cosmos and Ethereum components. One of those crashed and I lost the logs. I’m not sure if my validator stopped because of an isolated issue or if it was related to the outage that was resolved last week.
Another issue I had was that I had to run a full Ethereum node as part of the process. In theory, you should only need to run a partial node but at the time there was an issue that required running a full node. I get over 1.2TB in monthly data transfer with my home’s internet connection. I started getting usage warnings from my ISP. This is my first time mining from home, so I’m surprised to be hitting bandwidth issues at such a small scale.
Updates on running a Helium hotspot
It has been almost 30 days exactly since I set up my first Helium hotspot and my second one will arrive next week. At the moment, I’m using a 8-foot, 9.2 dBi Comet antenna.
So far, I’ve earned 94.55 HNT or over $1,000 at current HNTUSD prices ($11.37). I wonder if the hotspot would see more traffic if I mounted it just a little higher. It currently misses a lot of beacons that other hotspots nearby and higher pick up. I also want to try switching to a lower gain antenna like the one from HNTenna.