This project is intended to be an example of implementing a minimal social network on Solana blockchain. It consists of a smart contract (written in Rust) that contract that can be deployed on localnet (at the moment) and also a typescript library that provides interaction means with the smart contract API.
- Rust 1.57.0
- node 17.3.0
- npm 8.3.0
- solana 1.9.3
- Linux system (the project was developed on Ubuntu, but it might work on MacOS/Windows as well, with the required bootstrap).
-
We must install
solana-cli-tools
as (here)[https://docs.solana.com/cli/install-solana-cli-tools#macos--linux],rustup
& latest version ofRust
(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
), nvm (curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
) & node (nvm install 17.3.0 && nvm use 17.3.0
).npm
should be installed by installingnode
withnvm
. -
Next up, start a validator in a bash terminal:
solana-test-validator
. You might need to create first a file based wallet:solana-keygen new
. The wallet keypair should be present on$HOME/.config/solana/id.json
. -
Run in another terminal
solana logs
. -
Clone this repo, enter it and run
npm install
. -
Run
npm run build:program-rust
. -
Run
npm run deploy
-
First, we need the addresses of some friends. Since is hard to find friends nowdays, we're going to make some fake ones: Alice and Bob. We generate keypairs for both of them:
a.
mkdir users && solana-keygen new --outfile users/alice-keypair.json
.b.
solana-keygen new --outfile users/bob-keypair.json
.c.
solana airdrop 1 <alice_pubkey> && solana airdrop 1 <bob_pubkey>
. -
Once this is done, we proceed to adding some friends to our current empty friends list:
a.
solana-keygen pubkey users/alice-keypair.json && solana-keygen pubkey users/bob-keypair.json
.b.
npm run start -- --add=<alice-pubkey>
.c.
npm run start -- --add=<bob-pubkey>
. -
Let's see who's online:
npm run start -- --friends
. -
If all friends are offline, let's set the status of one of them to online:
npm run start -- --payer-keypair-path=users/alice-keypair.json --online=true
. -
Let's see again who's online:
npm run start -- --friends
. -
Let's set Alice status as offline:
npm run start -- --payer-keypair-path=users/alice-keypair.json --online=false
. -
Let's see again who's online:
npm run start -- --friends
. -
Let's set Bob status as online:
npm run start -- --payer-keypair-path=users/bob-keypair.json --online=true
. -
Let's see again who's online:
npm run start -- --friends
. -
Let's remove Bob from friends list (nothing personal):
npm run start -- --remove=<bob-pubkey>
. -
Let's see again who's online:
npm run start -- --friends
.