NEAR Library is a smart contract where you can to create, rate, comment, store and transfer books using the NEAR protocol, making a library online where you can request one book and change the owner. The following are the main functionalities of this smart contract:
- Add a Book to the library.
- Get all the list of Books.
- Get only the books that you added.
- Rate a book.
- Add a comment where you describe why do you liked... or not.
- Transfer the book to another Owner.
To run this project locally you need to follow the next steps:
-
Make sure you've installed [Node.js] ≥ 12 (we recommend use [nvm])
-
Make sure you've installed yarn:
npm install -g yarn
-
Install dependencies:
yarn install
-
Create a test near account [NEAR test account]
-
Install the NEAR CLI globally: [near-cli] is a command line interface (CLI) for interacting with the NEAR blockchain
yarn install --global near-cli
Configure your near-cli to authorize your test account recently created:
near login
Build the NEAR library smart contract code and deploy the local development server: yarn build:release
(see package.json
for a full list of scripts
you can run with yarn
). This script return to you a provisional smart contract deployed (save it to use later). You can also follow the instructions on the folder scripts.
The following commands allow you to interact with the smart contract methods using the NEAR CLI (for this you need to have a provisional smart contract deployed).
Information: the command for rate will require especific data (AccountId, Rate)
Rate values:
- The value 0 represents a bad rate.
- The value 1 represents a regular rate.
- The value 2 represents a awesome rate.
near call $CONTRACT AddBook '{"isbn": "string","name":"string","description":"string","numpage":"number","author":"string","datepublished":"date","editions":"number"}' --account-id <your test account>
near view $CONTRACT getBooks
near view $CONTRACT getBook '{"id":int}'
near view <your deployed contract> getNBooks
Thing that we can add in the future
near call $CONTRACT rate '{"id":3,"valor":2}' --accountId joehank.testnet
near call $CONTRACT rate '{"id":3}' --accountId joehank.testnet
near call $CONTRACT comment '{"id":3,"comment":"i love it"}' --accountId joehank.testnet
near call $CONTRACT getComments '{"id":3}' --accountId joehank.testnet
https://www.figma.com/file/I7oewIevwZP5LAAsPOUel0/Untitled?node-id=7%3A49