Communite is a smart contract that allows citizens to create and store complaints or suggestions about the state of their community using the NEAR protocol in order to have a transparent, reliable and safe space where they can express their problems. The following are the main functionalities of this smart contract:
- Create a complaint or suggestion.
- Get all the complaints living on the smart contract to know your status (Submited, In progress and Done).
- Get only the complaints that I already create.
- Vote on a complaint or suggestion from other to give more weight.
- Change the status of a complaint (Submited, In progress and Done) if I'm the 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 communite smart contract code and deploy the local development server: yarn buildevploy
(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)
Congratulations, now you'll have a local development environment running on the NEAR TestNet! 🥳
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 commands will require especific data (category, status)
Category values:
0. the value 0 represents a Lights problem.
1. the value 1 represents a Street problem.
2. the value 2 represents a Neighborhoodh problem.
3. the value 1 represents a Water problem.
near call <your deployed contract> addNewComplaint '{"title": "string","description":"string","category":integer,"location":"string"}' --account-id <your test account>
near view <your deployed contract> getComplaints
near call <your deployed contract> getNumberOfComplaints --accountId <your test account>
near view <your deployed contract> getNComplaints
near view <your deployed contract> getComplaintInfo '{"id":integer (id from you complaint)}' --accountId <your test account>
near call <your deployed contract> voteComplaint '{"id":integer (id from you complaint)}' --accountId <your test account>
near call <your deployed contract> removeVote '{"id":integer (id from you complaint)}' --accountId <your test account>
Command to change the status (Submited to In progress) of a complaint if you are not the complaint owner (you need to be the solver of the complaint):
near call <your deployed contract> takeComplaint '{"id":integer (id from you complaint)}' --accountId <your test account>
near call <your deployed contract> finishComplaint '{"id":integer (id from you complaint)}' --accountId <your test account>
Command to change the status (Submited to In progress and In progress to Done) of a complaint if you're the complaint owner:
near call <your deployed contract> finishComplaint '{"id":integer (id from you complaint)}' --accountId <your test account>
Testing is a part of the development, then to run the tests in the communite smart contract you need to run the follow command:
yarn test
this will execute the tests methods on the assembly/__tests__/main.spect.js
file
This is a explanation of the smart contract file system
├── README.md # this file
├── as-pect.config.js # configuration for as-pect (AssemblyScript unit testing)
├── asconfig.json # configuration file for Assemblyscript compiler
├── assembly
│ ├── __tests__
│ │ ├── as-pect.d.ts # as-pect unit testing headers for type hints
│ │ └── main.spec.ts # unit test for the contract
│ ├── as_types.d.ts # AssemblyScript headers for type hint
│ ├── index.ts # contains the smart contract code
│ ├── models.ts # contains code for the models accesible to the smart contract
│ └── tsconfig.json # Typescript configuration file
├── neardev
│ ├── dev-account #in this file the provisional deploy smart contract account is saved
│ └── dev-account.env #in this file the provisional deploy smart contract account is saved like a environment variable
├── out
│ └── main.wasm # compiled smart contract code using to deploy
├── package-lock.json # project manifest lock version
├── package.json # Node.js project manifest (scripts and dependencies)
└── yarn.lock # project manifest lock version
- The smart contract code lives in the
/assambly
folder. - To make a test deploy use the scripts in the
/package.json
file.