Setup a local development environment for building onchain programs.
anchor init
to create a new blank Anchor projectanchor test
runs your tests, and also builds your code.solana -V
should show solana-cli 1.18.x
(any number for x
is
fine).
anchor -V
should show anchor-cli 0.30.0
.
anchor test
command should complete with no errors or warnings.
However you may encounter issues, and we’ll fix them below:
package
solana-program v1.18.12 cannot be built because it requires rustc 1.75.0 or newer
errorcargo add solana-program@"=1.18.x"
, where x
matches your version of
solana-cli
. Then re-run anchor test
.
Error: Unable to read keypair file
.config/solana/id.json
. You can either copy a keypair from an
.env
file (just the array of numbers) into a file or use the command
solana-keygen new --no-bip39-passphrase
to create a new keypair file. Then
re-run anchor test
.
unused variable: 'ctx'
warninginitialize
instruction handler isn’t doing anything yet.
You can open programs/favorites/src/lib.rs
and change ctx
to _ctx
or just
go onto the next step.
No license field in package.json
warning"license": "MIT"
or "license": "UNLICENSED"
depending
on preferences
anchor test
completes successfully - with no warnings and no errors -
before continuing.