A family of smart contracts developed for NEAR Protocol to enable crowd-sourced civic development. Think Kickstarter for neighborhood projects.
View the Project on GitHub Learn-NEAR/NCD.L1.sample--nearly-neighbors
A family of smart contracts developed for NEAR Protocol to enable crowd-sourced civic development. Think Kickstarter for neighborhood projects.
Any content produced by NEAR, or developer resources that NEAR provides, are for educational and inspiration purposes only. NEAR does not encourage, induce or sanction the deployment of any such applications in violation of applicable laws or regulations.
The contracts provided here enable users to propose neighborhood development projects and crowd-source funding for them.
Think of it like Kickstarter, but instead of funding your roommate’s sister’s math rock band, you’d propose and fund projects like a new local park, grocery store, or community center. And the whole thing is powered by the NEAR protocol, so identity and financial tools are built in.
For the sake of this explanation, we’ll assume three users: Alice, Bob, and Carol.
This repository is an example of a dApp seed project. dApp seed projects provide a stable foundation for developers to build a distributed application on top of. This includes:
yarn install
(or npm install
)yarn build
(or npm run build
)yarn test
(or npm run test
)src/
See below for more convenience scripts …
Compile source to WebAssembly
yarn build # asb --target debug
yarn build:release # asb
Run unit tests
yarn test:unit # asp --verbose --nologo -f unit.spec
Run simulation tests
These tests can be run from within VSCode (or any Rust-compatible IDE) or from the command line.
NOTE: Rust is required
yarn test:simulate # yarn build:release && cargo test -- --nocapture
Run all tests
yarn test # yarn test:unit && test:simulate
More wireframes can be found in the wireframes/
folder. Here are some examples showing how we envision the basic user interface elements.
Create a Proposal
Supporting a Proposal
Map of Projects
This contract is designed to be self-contained and so may be extracted into your own projects and used as a starting point. If you do decide to use this code, please pay close attention to all top level files including:
package.json
: JavaScript project dependencies and several useful scriptsasconfig.json
: AssemblyScript project (and per contract) configuration including workspace configurationas-pect.config.js
: as-pect unit testing dependencysrc/tsconfig.json
: load TypeScript typessrc/as_types.ts
: AssemblyScript types header filesrc/as-pect.d.ts
: as-pect unit testing types header fileCargo.toml
: Rust project dependencies and configurationCargo.lock
: version-locked list of Rust project dependenciesThe core file structure:
nearly-neighbors
├── README.md <-- this file
├── build <-- compiled contracts (WASM)
│ ├── debug
│ └── release
├── simulation
│ ├── Cargo.toml <-- simulation test config
│ └── src <-- simulation tests
│ ├── factory.rs
│ ├── lib.rs
│ ├── project.rs
│ └── proposal.rs
├── src
│ ├── factory <-- factory contract with:
│ │ ├── asconfig.json
│ │ ├── assembly <-- source code
│ │ │ └── index.ts
│ │ └── __tests__ <-- unit tests
│ │ └── index.unit.spec.ts
│ ├── project <-- project contract with:
│ │ ├── asconfig.json
│ │ ├── assembly <-- source code
│ │ │ └── index.ts
│ │ └── __tests__ <-- unit tests
│ │ └── index.unit.spec.ts
│ ├── proposal <-- proposal contract with:
│ │ ├── asconfig.json
│ │ ├── assembly <-- source code
│ │ │ └── index.ts
│ │ └── __tests__ <-- unit tests
│ │ └── index.unit.spec.ts
│ └── utils.ts
└── wireframes <-- wireframe images
There are three contracts that make up this project.
By breaking out the logic into multiple contracts, we are employing NEAR development best practices which will make the code more secure (through rigorous testing of separated concerns) and robust (enabling complex features through cross-contract calls).
The proposal contract represents a user’s proposed idea for a development project.
Proposals are created by users (mediated by the factory) and hold data like:
The proposal accepts funding from supporters.
If proposals are fully funded by their due date, then they are closed and converted to a project (with all funds transferred to the new project’s account). If proposals do not meet their funding goals, then they are closed and all funds are returned to the supporters.
The project contract represents a fully-funded proposal. It is managed by a project owner, who is authorized to access the project’s NEAR tokens so that they can put those funds into use by actually executing on the real-world project.
Projects are created automatically by the factory from a fully-funded proposal. Projects maintain a reference to their original proposal for proper record-keeping.
Projects track their own real-world progress by reporting on key stats like:
The factory is a behind-the-scenes contract which takes care of the creation and setup of proposals and projects. Instead of human users creating proposal and project contracts directly, they instead send requests to the factory which handles the necessary tasks for them.
This is a pattern you’ll see frequently in NEAR (and other blockchain) development: designating a contract with the responsibility for managing the lifecycle of other contracts. It helps abstract out the routine tasks of contract initialization and setup, limiting tedious user interactions and thus avoiding potential for user error.
TODO: Add referral to resources for deploying
There are two main ways you can contribute to this project:
Interested in creating your own dApp seed and earning rewards for your efforts? Learn more: [TODO: ADD LINK / MORE COPY].
Some ideas for future feature development: