Solana From Source
Solana is an interesting blockchain project that promises to be an L1 with low gas fees and fast block times. To check it out I decided to try and create some test smart contracts on it. However, their binary releases are only for OSX x86 and, as of yet, no OSX arm64 binaries are provided. So to get things to still run I had to build what I needed from their main repo.
To build Solana on an M1 system and run the Hello World example you will need Rust. You can install it via rustup.rs. Once rust is installed, we can clone Solana master and install everything we need to deploy the example smart contract to devnet.
Build Solana Master
As of writing this guide, the latest 1.7.1 release of Solana does not build on an M1 system. Nonetheless, the master branch already does have some commits to support M1 (e.g. commit 8a9b7f5
).
Clone the Solana repo, and cd into it:
$ git clone https://github.com/solana-labs/solana
$ cd solana
Next, you can try running the script scripts/cargo-install-all.sh
as described in the Solana Tool Suite Guide. However, for me this script did not work out of the box. It uses some scripting to find your cargo
installation but it had trouble on my system. To work around it I simply edited the script to use cargo
from the path:
#cargo="$("${readlink_cmd}" -f "${here}/../cargo")"
cargo="cargo"
Now you should be able to build Solana without problems:
$ ./scripts/cargo-install-all.sh --validator-only .
We use the validator-only
switch here because building the spl-token-cli
is practically impossible at the moment. This program is located in the Solana Program Library repo which currently has a dependency on Solana 1.6.11
. A nightly build with a dependency on master would be nice :)
After the script finishes, you should have all the validator binaries in the ./bin
folder. To keep things simple, add this bin
folder to your path. It excludes the solana-test-validator
however, but that one does not seem to work correctly with M1 system anyway so no matter. If you do wish to give it a try though you can compile it with the following:
$ cargo build --release --bin solana-test-validator
$ cp target/release/solana-test-validator ./bin
Now the test validator should also be in the bin
folder.
Set Up Solana
Now that we have the solana
binary we can configure it to use devnet:
$ solana config set --url https://api.devnet.solana.com
Create a new key pair:
$ solana-keygen new
With the newly generated keypair, we can request an airdrop of some SOL:
$ solana airdrop 5
This will add 5 SOL to our wallet which we can use to deploy smart contracts to the devnet.
Setup BPF SDK
To be able to deploy the hello world program onto the test validator, you will need to setup the BPF SDK. You can do that by going to sdk/cargo-build-bpf
from the project root. From there, run the following:
$ cargo install --path .
This will install the cargo-build-bpf
program to ~/.cargo/bin
. Next in ~/.cargo/bin
create a symlink to the sdk
folder in the project’s bin
folder, like so:
$ ln -s $PROJECT_ROOT/bin/sdk ~/.cargo/bin/sdk
Replace $PROJECT_ROOT
with your Solana project folder.
Compile Hello World Smart Contract
With all the binaries now created, we can compile the Hello World example program. Clone it somewhere and inside the project folder run the following:
$ cargo build-bpf \
--manifest-path=./src/program-rust/Cargo.toml \
--bpf-out-dir=dist/program
If all went well, the smart contract should now be compiled. You can deploy it to devnet as follows:
$ solana program deploy ./dist/program/helloworld.so
Done! The hello world example smart contract is now deployed to devnet.
Join Coinmonks Telegram Channel and learn about crypto trading and investing
Also, Read
- The Best Bitcoin Hardware wallet | BitBox02 Review
- BlockFi vs Celsius | Hodlnaut Review | KuCoin Review
- Bitsgap review | Quadency Review | Bitbns Review
- Crypto Copy Trading Platforms | Coinmama Review
- Coinbase Review| Deribit Review |FTX Review | StealthEX Review
- NGRAVE ZERO review | Phemex Review | PrimeXBT Review
- Best Blockchain Analysis Tools | Earn Bitcoin | Swapzone Review
- Crypto arbitrage Guide | How to Short Bitcoin | Prokey Review
- Binance Trading Bots | OKEx Review | Atani Review
- Best Crypto Trading Signals Telegram | MoonXBT Review
- Godex.io Review | Invity Review | BitForex Review