Solana Development for absolute beginners

I.

Solana is the fastest blockchain that exists right now. It is also decentralized, permissionless and censorship-resistant. It is one of those blockchains that is ready for mass adoption at scale, and that’s one of the reasons I’ve been picking it up and learning how to build on it.

But if there’s one drawback of Solana, it’s that there is very little supplementary learning material out there for developers. When I started a few months ago, it was even less, but that’s slowly changing.

The documentation on their site is vast and extensive. You’re going to have to do a lot of reading just to understand the basics, let alone diving into how it all works under the hood.

A couple of things can give you a head start, which are-

If you know front-end development, you can leverage your skills in Javascript, Typescript and React and make use of Solana Web3js to handle client side programming.

If you don’t know Rust, you can either make your life a living hell by learning to program in Rust and handling all the low-level yourself, or use one of the best development frameworks for handling the low-level stuff- Anchor.

If you’re coming from an EVM based blockchain, you should be able to adjust yourself to the ecosystem within a few months of consistent effort or learn how to leverage your existing skills using things like Neon Labs, or Solang.

I like to spend my time exploring different things which are at the bleeding edge of technology, mostly because I’m curious and incredibly excited about what’s happening in technology all around the world, and not at all because my social life solely consists of going out once a month and drinking till 3 AM.

With that said, I’ve been diving deep into the Solana ecosystem over the past few months and I’m so bullish with what I’ve seen what it can do, that I’ve started to build my project of a decentralized nation on top of it.

There are few reasons why developer tutorials, and mainly beginner-friendly developer tutorials, are lacking in this space-

1. Things are changing at a rapid space, and tutorials written today have a very good chance of being irrelevant in a few months.

2. Developers who already get past the glass-eating learning phase usually start building something on their own or join a company in this space and work on something exciting, or simply continue to work on open-source projects to further their learning.

In this (hopefully) brief series, I won’t make any assumptions about your development experience other than the fact that you know something about basic CS.

I’m here to show you that it can be easy to get started, that it doesn’t have to be overwhelming, and leave you with the idea that you can start building in one of the best blockchains that exists right now.

If you’re already a developer on Solana, this isn’t a guide for you and it might feel woefully simple to even make a tutorial on. This guide is for your friend who is on the brink of changing to a web3 career, or that friend who told you they’d learn Solana with you, went through the developer documentation and strangely stopped texting you back.

Let’s get started.

II.

Install Linux or WSL2 (if you’re on MacOS, you can skip this),

NodeJS (use NVM to install the latest LTS),

Node Package Manager,

The Solana CLI suite,

VSCode.

Clicking on each of those above links will show you a way how to do it easily.

We will be playing around with the Solana Web3js library in this program.

Go ahead and create a file called “createcon.ts”

.ts stands for typescript, which is just JavaScript with strict type-checking.

We start our journey with one line at the top-

 import { Connection } from "@solana/web3.js";

We will build a connection to the Solana blockchain and display the current version of Solana we’re using. To build a connection to the JSON RPC full-node endpoint, we must first import “Connection” from the @Solana/web3.js library, which is what we have done above.

One question you might have now is, where does the library come from? It’s certainly not your computer. And you’re right. We first need to install the package, and nodeJS handles that for us. But it is not automatic.

You need to create a separate package.json file with the following code-

{
"scripts" : {
"dependencies":  {      
"@solana/web3.js": "^1.28.0",
}
}

Now, before running the program for the first time, you have to open your terminal and run this command-

npm i

This will let the node package manager to install all the dependencies in your program. Does this mean that you have to know node?

Absolutely not. But it helps, like I’ve said before. While learning to build on the Solana blockchain, you’ll inevitably learn to pick up all sorts of new web technologies both on the front end, and on the backend. But there’s no written rule out there that says that you have to know everything before you start.
Take JavaScript for example. It’s an incredibly powerful language and has been around for over a decade, but absolutely no one knows everything about JavaScript. Does that stop people from building things with JavaScript?
It doesn’t.

Often you just need to know 20% of a language to start off, and you will figure out the rest of the 80% on the road. Developing in Solana is also like that, except the rest of the 80% would usually take you a long time and no one’s holding your hand for the first 20%. Things are still changing (for the better) for developers every day and being early has its perks.

Anyway, let’s get back to the code. We start with an asynchronous function to fetch information and write that.

Asynchronous functions are easy to understand. They’re basically equivalent to saying, “Hey, here’s this thing I want to do, but it also requires something that will take time to come, so keep the program running and bring that thing back so that it runs with the program.”

Every web app which leverages APIs depends on asynchronous calls, because that always takes some time to come back. Here, we’re requesting information from the Solana blockchain which is, in essence, a similar kind of call. Easy, right?

async function main() {

const url = "http://localhost:8899";


let connection = new Connection(url);

const version = await connection.getVersion();

console.log("Connection to cluster established:", url, version);

main().then(

() => process.exit(),

(err) => {

console.error(err);

process.exit(-1);

}

);

That’s it. You’ve successfully coded your first program that reaches out to the Solana blockchain, gets some information and shows it to you. But how do we run it?

Well, if you see the second line, it says that it’s supposed to run on the local network. But we haven’t set up anything locally yet, right?

We need to do that, by setting up something called a “Test Validator.”

What is a validator?

Validators form the backbone of Solana’s network by processing transactions and participating in consensus. Centralized services don’t require validators, but decentralized blockchains do, and these validators are what make the blockchain censorship resistant and secure.

The Bitcoin equivalent of validators are miners, who help to maintain the decentralized ledger. Just like anyone can become a Bitcoin miner, anyone can become a Solana validator.

However, just like a mining rig is costly for most people, so is becoming a Solana validator (at the time of this writing). Hence, we have a test-validator, which runs a testing version of the validator on our computer.

Before we trigger it, we have to make sure we’re on the local net.

Run this command on your terminal first-

solana config get

If you see that we’re on the devnet, or worse, on the mainnet, it’s time to change that to the local network.

solana config set --url localhost

Now, if you run solana config get again, you should see that it’s pointed to your local network.

Now, start the validator with this command-

solana-test-validator

You should see a validator running, processing hundreds of blocks per second. For other blockchains to do the same thing, is close to 0. It’s a beautiful thing to watch, but it’s far more beautiful to play around with.

Now, to run our program, open a terminal in VSCode, and run this-

npx ts-node -s createcon.ts

You should see an output that indicates the version. That’s it! It compiled and worked. If you get any errors at this stage, you should either go back and check everything, copy-paste everything, and try again.

If you get an error again, use google, reach out to the Solana discord and ask, and if you find out that the error is because something changed over time, feel free to comment below this post and let me know.

III.

Anyway, we just found out what version our Solana is, but what other things can we find out?

If you go check out the connection page on the API reference, there are a couple of things we find out-

Copy paste this before the main.then() method, and run it again-

const epochschedule = await connection.getEpochSchedule();

const clusternodes = await connection.getClusterNodes();

const slot = await connection.getSlot();

const blocktime = await connection.getBlockTime(slot);



console.log("Epoch schedule:", epochschedule);

console.log("Cluster nodes- :", clusternodes);

console.log("Slot:", slot);

console.log("Block time :", blocktime);

}

We are now trying to find a couple more things. What is the epoch schedule? What slot are we on? What cluster nodes are we connecting to? What is the block time?

We should be getting a log of everything we asked for when we run this program again. Now, you might have some questions.

What is an epoch schedule? What are slots? What is the block time and how are they different from slots? What are cluster nodes?

These are things that you should look into the Solana documentation for. Everything is defined there, and it’s fairly easy to understand and play around with.

Once you get the hang of it, you’ll be utilizing this library to create tokens, stake accounts, and so on. Having a firm grasp of this library will also allow you to write client side code for other existing open-source Solana projects, and there are many of them out there already.

But if you’ve read this far, and followed along, I have to confess something before finishing this essay.

IV.

Programming on Solana is not easy. There’s a popular term in the developer community to fondly refer to the painful process of handling low-level details of it, called “Glass eating” and it means exactly what you think it means. Sooner than later, in every language, to do something exceptional, you have to go through some kind of a glass eating phase. Solana is no different, and there’s no one to hold your hand along the way.

But if it were easy, everyone would do it. It is not easy, but it is a worthy challenge to take on. By choosing to learn the ins and outs of a growing blockchain system, you’ll be teaching yourself a lot of things. You’ll teach yourself the basics of –

  1. Rust
  2. Anchor
  3. Javascript
  4. React or Svelte or an equivalent front end framework
  5. Back end like node, express, mongo and then specialize in decentralized solutions like IPFS.

And that’s just to get started. Along the way, you’ll have to dive in head-first into a lot of things which may be Unreal or Unity if you want to build blockchain games or create VR experiences (Hint: Choose Unreal), look into C++ or C# again, pick up GraphQL over the weekend, and the list goes on, but at the end of the day, you’ll be a better developer. You’ll be further along than everyone who shows up to the ecosystem in three years.

Blockchains are a crucial technology of the future, and I believe Solana will be the place where all the major innovations take place. It is fast, scalable, and it doesn’t price out retail investors and newcomers that Ethereum does. Developing for Solana now, is like starting a job at Apple in the 90s. Web3 will be better than Web2 and this is the best time to bite the bullet, chew the glass and dive headfirst into it all.

Soon, you might get a lucrative job or build something truly revolutionary, but the best part about it will be the journey that you’re embarking on now.

I consider myself a beginner still. Not a day goes by without me learning something new or discovering something amazing. I’ve had the privilege of getting stuck multiple times and I’ve always had others help me out in Solana’s discord and other ecosystem projects discord channels. But if there’s someone who truly caused me to not give up, it was Jordan (the creator of Metaplex, the project that built the backbone for NFTs on Solana). When I was starting out and feeling overwhelmed, I decided to reach out and ask developers how long it took them to get confident in their skills.

Jordan told me that he started in January of this year and had been at it for just 6 months at a time. He advised me to keep at it and start off with the JavaScript side of Solana before diving into the rust side of it. So, Jordan, if you’re reading this, thank you! His advice worked, and it is also why I chose to introduce the client side code to make you familiar with how simple starting out in Solana can be.

Once you’re done with this- go through the resources mentioned in this excellent guide- https://github.com/ilmoi/solana-onboarding

I’ll be writing more stuff about Solana, crypto and blockchains in general, so you can sign up below to not miss out on any alpha-

If this post added value and helped you along, pass it on and remember that when you’re a Solana wizard, pay it forward by helping those getting started.

Good luck! WAGMI!

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s