This project demonstrates how to use the Solana Javascript API to interact with programs on the Solana blockchain.
The project comprises:
- An on-chain hello world program
- A client that can send a "hello" to an account and get back the number of times "hello" has been sent
The following dependencies are required to build and run this example, depending on your OS, they may already be installed:
- Install node (v14 recommended)
- Install npm
- Install Rust v1.56.1 or later from https://rustup.rs/
- Install Solana v1.10.35 or later from https://docs.solana.com/cli/install-solana-cli-tools
If this is your first time using Rust, these Installation Notes might be helpful.
If you're on Windows, it is recommended to use WSL to run these commands
- Set CLI config url to localhost cluster
solana config set --url http://127.0.0.1:8899
- Create CLI Keypair
If this is your first time using the Solana CLI, you will need to generate a new keypair:
solana-keygen new
npm install
There is both a Rust and C version of the on-chain program, whichever is built last will be the one used when running the example.
npm run build:program-rust
npm run build:program-c
solana program deploy dist/program/helloworld.so
npm run start
To customize the example, make changes to the files under /src
. If you change
any files under /src/program-rust
or /src/program-c
you will need to
rebuild the on-chain program and redeploy the program.
Now when you rerun npm run start
, you should see the results of your changes.