This project demonstrates how to use the Solana Javascript API to build, deploy, and interact with programs on the Solana blockchain, implementing a simple feed of messages To see it running go to https://solana-example-messagefeed.herokuapp.com/
First fetch the npm dependencies, including @solana/web3.js
, by running:
$ npm install
The example connects to a local Solana network by default.
To start a local Solana network run:
$ npm run localnet:update
$ npm run localnet:up
Solana network logs are available with:
$ npm run localnet:logs
For more details on working with a local network, see the full instructions.
Alternatively to connect to the public testnet, export LIVE=1
in your
environment. By default LIVE=1
will connect to the
beta testnet. To use the edge testnet instead define export CHANNEL=edge
in
your environment (see url.js for more)
Two versions of the program are provided, one written in C and the other
in Rust. The build process for each produce the same a BPF ELF shared object called dist/program/messagefeed.so
. They are interchangable so just pick one to use.
$ V=1 make -C program-bpf-c
or
$ npm run build:bpf-c
$ ./program-bpf-rust/build.sh
or
$ npm run build:bpf-rust
The message feed program is deployed by the web server at src/server.js
, so
start it first:
$ npm run start-server
After building the program and starting the web server, you can view the current message feed by running
$ npm run start
and post a new message with:
$ npm run start -- "This is a message"
After building the program and starting the web server, start the webapp locally by running:
$ npm run dev
then go to http://localhost:8080/ in your browser.