DEV Community

Cover image for How to make Solana Test Validator work with a Macbook with M1 chip
codenjobs
codenjobs

Posted on • Originally published at codenjobs.com

How to make Solana Test Validator work with a Macbook with M1 chip

If you have a Macbook with m1 chip and had trouble installing some tools for Solana dev, this post can be very helpful to you.

You can see the latest post at our website.

If you are new to Solana, please read this post first.

You can see many people reporting with this issue here.

My first approach to solve this was to use Docker but failed.

Then, I read the GitHub README file from Solana and it says we need to use Rosetta.

You can see this blog post for that and use this command if you don't have it installed at your laptop.

$softwareupdate --install-rosetta
Enter fullscreen mode Exit fullscreen mode

You can also use this post as a reference.

When you have the other terminal for Intel architecture with Rosetta ready, you can download Solana source code with this.

$git clone https://github.com/solana-labs/solana.git
Enter fullscreen mode Exit fullscreen mode

Test the commands below inside the Intel terminal with Rosetta.

If you have an issue with Solana Test Validator, it is likely you have Solana command working but not with solana-test-valdator to test solana locally and others such as solana-keygen to make a test Solana account.

You can simply use $cargo build and $cargo test to test all Solana projects work. But, you will find your computer become very hot if you compile all and it will cost its battery life and a lot of time to wait for it to compile.

So, instead of compiling all Solana projects, you can only do it with what you want to use. For example, to use solana-test-validator, you can visit validator folder and use the files in there.

$cd solana/validator
Enter fullscreen mode Exit fullscreen mode

and you will see solana-test-validator bash file with this code.

#!/usr/bin/env bash

here="$(dirname "$0")"
set -x
exec cargo run --manifest-path="$here"/Cargo.toml --bin solana-test-validator -- "$@"
Enter fullscreen mode Exit fullscreen mode

When you test it with $bash solana-test-validator, this will run solana-test-validator and show the log similar to this after you wait for the project compile.

Ledger location: test-ledger
Log: test-ledger/validator.log
⠠ Initializing...

Version: 1.8.0
Gossip Address: 127.0.0.1:1024
TPU Address: 127.0.0.1:1027
JSON RPC URL: http://127.0.0.1:8899
Enter fullscreen mode Exit fullscreen mode

This is already helpful if you had hard time attempting to install solana-test-validator at your laptop. But, this is not permanent. So, tweak the solana-test-validator file similar to this.

What we do here is to build the compiled file instead of running it.

#!/usr/bin/env bash

# https://github.com/solana-labs/solana

here="$(dirname "$0")"
set -x
exec cargo build --release --manifest-path="$here"/Cargo.toml --bin solana-test-validator -- "$@"
Enter fullscreen mode Exit fullscreen mode

Then, use $bash solana-test-validator again. When the compile process ends, you will be able to find solana-test-validator at solana/target folder.

You can test it work with $./solana-test-validator if you are in the target folder and you will see the log similar to what you saw before with the previous bash command.

We now have reusable binary file but it is not callable directly with $solana-test-validator command. So, you can move it to where other binary files saved.

For example, you can find where git, anchor or other files are installed with these.

$where git
$where anchor
Enter fullscreen mode Exit fullscreen mode

For my Macbook with M1 chip, /opt/homebrew/bin was one of the options where similar files were. Move your solana-test-validator file where you want with the command similar to this.

// Use this at solana/target folder
$mv ./solana-test-validator /opt/homebrew/bin 
Enter fullscreen mode Exit fullscreen mode

Then, you can test $solana-test-validator again and you will see it working without any issue.

The information below is not relevant to solana-test-validator but can be helpful also.

When I installed the Solana CLI Tools following the instructions here with this command

$sh -c "$(curl -sSfL https://release.solana.com/v1.7.14/install)"
Enter fullscreen mode Exit fullscreen mode

I had to use this repeatedly to use $solana command.

$PATH="/Users/codenjobs/.local/share/solana/install/active_release/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

You can solve this issue by making a symbolic link. Use command similar to this with your mac username instead of codenjobs below.

$sudo ln -s /Users/codenjobs/.local/share/solana/install/active_release/bin/solana /Users/codenjobs/.cargo/bin/solana
Enter fullscreen mode Exit fullscreen mode

Then, you will be able to use $solana command again without need to set $PATH everytime.

If you need solana-keygen CLI also, you can move to solana/keygen folder and use $cargo build --release and repeat the similar process you did to make solana-test-validator work previously.

Test all these worked while solana-test-validator is running at another terminal.

$mkdir ~/my-solana-wallet
$solana-keygen new --outfile ~/test-wallet/my-keypair.json
Enter fullscreen mode Exit fullscreen mode

This will show log similar to this.

Wrote new keypair to ./test-wallet/my-keypair.json
=============================================================================
pubkey: <YOURS>
Enter fullscreen mode Exit fullscreen mode

Then, confirm you are on localnet with $solana config get or set it to localhost (solana-test-validator) with this $solana config set -u localhost command.

Airdrop Solana to the account you made with $solana-keygen previously.

$solana airdrop 5 <YOURS> --url localhost
Enter fullscreen mode Exit fullscreen mode

You can test your balance with $solana balance and it will show you have 500000005 SOL enough to test locally whatever you want to develope with Solana.

If you are searching for a Solana dev job, you can find it here at our website or our Telegram group or register to Code&Jobs website, share your profile and show your skills.

Discussion (0)