Skip to content

bunnyBites/learn-solana-with-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Let's test Solana with the local environment first with Rust.

If you haven't installed Rust, now will be a good time:

The following steps are taken from the official Solana documentation:

  1. Solana in the local environment
  2. Keypair and wallets
  3. SolDev course

Setup for Linux system (terminal):

  1. Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install Solana CLI (this CLI is used to run our program locally):
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

If the above command throws a path that you need to add:

export PATH=<THROWN_PATH>:$PATH

replace THROWN_PATH with the path you received in step 2.

  1. Check if the local setup is complete:
  solana --version

If you get an error, you can restart your terminal or system to ensure the PATH is updated You can also check your PATH by running this command in the terminal:

echo $PATH

The path should have something like this:

/home/bunny/.local/share/solana/install/active_release/bin

  1. Test your local-test-validator:
  solana-test-validator

If your setup succeeds, you will get many configuration details:

  --faucet-sol argument ignored, ledger already exists
  Ledger location: test-ledger
  Log: test-ledger/validator.log⠂ Initializing...                                                                               Waiting for fees to stabilize 1...
  Identity: 4QtjGtBQ5kfjfRq6yUqqaWngQ1oQoUGyozBZbbTKhyfi
  Genesis Hash: 5w6HtVfS1a9ESXLAG6TywZhCEFn9nVDe8oiB7cK7j8ij
  Version: 1.16.28
  Shred Version: 12150
  Gossip Address: 127.0.0.1:1024
  TPU Address: 127.0.0.1:1027
  JSON RPC URL: http://127.0.0.1:8899 -----> * URL passed to our code *
  WebSocket PubSub URL: ws://127.0.0.1:8900
  ⠒ 00:00:12 | Processed Slot: 1830 | Confirmed Slot: 1830 | Finalized Slot: 1798 | Full Snapshot Slot: 1702 | Incremental Snapshot Slot: - | Tr

This URL is what we need to pass in the code.

  1. You have successfully configured Solana in your local environment. You can now check the main.rs to get started.

  2. Output for our program:

SOLs Before airdropping -> 0
Transaction: 4WxHEwzZL6xv12b4rYALi4oV89TPNL93KXfZ1YSDwJwdHSweu Status: true
SOLs After airdropping -> 1

Creating keypair

Creating keypair is required throughout solana transactions. It's better to store specific values like public key and secret key in environment variables.

create a new keypair (wallet):

let keypair = Keypair::new();

get public keypair

let pubkey = Signer::pubkey(&keypair)

get secret for our keypair

let secret = keypair.to_base58_string()

Sample .env file

MY_PUB_KEY=JBFs2brb5KrFH1D9HqX2YF5JigySowHPN79gBSaoxKrR

OTHER_PUB_KEY=4uyGibipBrgE1Svsai4fg1BTaBWBMRTtxJKX7agFAdLe

MY_SECRET_KEY=28rUCoiLSWGdH6ToJU7tzrjS6oU5u9MbeRJhBh7HN4h26E1w8uZCigJVArNssFEnH3gzak2DSiYQfBWaHyN5FjGu

About

(D)Application to learn Solana with Rust from Scratch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages