Solana Development (4) —Develop Your own Local Solana Cluster

By Brochain | Solana Development | 24 Apr 2022


 

In Solana, all network is called a Cluster. So, its Mainet is a Cluster, Testnet is a Cluster. Now, this article walks you through how to develop your own Cluster on a local machine. It would be very helpful if you come to learn how to develop a Smart Contact (or it is called program in Solana) in upcoming articles. As usual, below demonstrations are all done in my Ubuntu 20.04 VPS. So, let’s begin:

Setup

Although I have already mentioned how to install Solana-CLI in the first post of this series, I find this installation method could not get my local cluster running. After a few Try-and-error, I find out that the installation has to be in below orderto launch your local cluster successfully:

1. Install Rustc, cargo, rustfmt

$ curl https://sh.rustup.rs -sSf | sh
$ source $HOME/.cargo/env
$ rustup component add rustfmt

2. Update Rust

$ rustup update

3. Install libssl-dev, pkg-config, zlib1g-dev, etc. On Ubuntu:

$ sudo apt-get update
$ sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang make

4. Install Solana-CLI:

sh -c "$(curl -sSfL https://release.solana.com/v1.8.0/install)"

My local cluster works fine as long as I install above components and dependencies in correct order. Then, you can start a local network by below command:

$ solana-test-validator--faucet-sol argument ignored, ledger already exists
Ledger location: test-ledger
Log: test-ledger/validator.log
Identity: FSPaif7DZK8Hsi2ozhnfRJRgR8KUSzvFXtAGPSV3zJb7
Genesis Hash: 3Q7oGGuWVihnUFFc4Z8WRrQy53ci2bZjF9vy8VsBnxcr
Version: 1.8.0
Shred Version: 27173
Gossip Address: 127.0.0.1:1024
TPU Address: 127.0.0.1:1027
\JSON RPC URL: http://127.0.0.1:8899⠙ 00:00:22 | Processed Slot: 5019 | Confirmed Slot: 5019 | Finalized Slot: 4987

If you see something like above, congratulations! you successfully spin up your cluster on your local machine.

Make a Fund Transfer

Most concept of creating wallet, making transfer using Solana-CLI has already discussed in the first post. So, I don’t repeat much here. If you aren’t familiar with it yet, go check it out before continue.

Now, leave the existing console running and open a new console. Then, create two wallets if you have not created any. Then, connect your wallet to your local Cluster by setting url path to RPC URL. In the case above, your local RPC URL is http://127.0.0.1:8899. So, you can connect with following command:

$ solana config set --url http://127.0.0.1:8899Config File: /root/.config/solana/cli/config.yml
RPC URL: http://127.0.0.1:8899
WebSocket URL: ws://127.0.0.1:8900/ (computed)
Keypair Path: /path/to/yourwallet.json
Commitment: confirmed

Now, try to check if your wallet and the validator shares the same genesis block:

$ solana genesis-hash3Q7oGGuWVihnUFFc4Z8WRrQy53ci2bZjF9vy8VsBnxcr

As shown above, the hash of the genesis shown is the same shown in the validator’s one. So, everything seems fine.

Now, input below command to log solana transactions:

$ solana logs

Let’s this command keep on running and open a new console. Use the new console to make a fund transfer:

$ solana transfer JC1qGm4wV8LHJwdpNFmG3KKW3uNpuANLecuaP2xiUj7 0.1

Then, up completion, you can check back the solana logs console. You would find its confirmation message like this:

$ solana logsStreaming transaction logs. Confirmed commitment
Transaction executed in slot 6469:
Signature: 2nKdz8iPJUEg1fYsy7gogLKajNCHzuYTSjxnv23etPTmKHjJtYduksa4dNHfaumtgFnKU1gRYqmvR2Zur5Xqhr3v
Status: Ok
Log Messages:
Program 11111111111111111111111111111111 invoke [1]
Program 11111111111111111111111111111111 success

So, now everything seems fine.

Conclusion

Congratulation! You have successfully run your local Cluster. In next article, we would introduce how to deploy a Smart Contract in your local Cluster. Stay tuned and see you soon!

             

 

 

How do you rate this article?


52

1

Brochain
Brochain

Web3 Developer. The best way to learn is to share what you learnt.


Solana Development
Solana Development

Welcome to my blog. This blog would be about Solana Development. So, if you are interested to know how to write smart contract, web3 programs in Solana, stay tuned! Cheers!

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.