OpenSquare Collaboration is an off-chain gas free collaboration platform. Currently, off chain voting has been implemented while bounties and paid questions are in the plan.
Off chain voting now support substrate based chains and assets on Statemine/Statemint.
The code is organized with yarn workspaces and make
sure yarn is installed before running it. There are 3 packages node-api
, backend
and next
under the packages
folder.
This package maintains multiple @polkadot/api instances or ethers JsonRpcProviders for target chains in case of a single endpoint failure. It is in charge of interaction with chain nodes and provides restful apis for caller to fetch on-chain data. The apis include:
- [chain]/balance/[address]/[blockHashOrHeight?]: get the address balance at a block(by block hash or height).
- [chain]/proxy/[delegator]/[delegatee]/[blockHashOrHeight?]: get the proxy info between 2 addresses.
- [chain]/chain/height: get current chain height.
- [chain(statemine|karura|bifrost)]/token/[assetId]/account/[account]/[blockHashOrHeight?]: get the token/asset balance by asset id.
- /evm/chain/[chain]/contract/[contract]/address/[address]/height/[blockHeight]: get ERC20 token balance from evm chains.
- /evm/chain/[chain]/contract/height/[timestamp?]: get evm chains height by time.
- /issuance/token/[token]/[blockHashOrHeight?]: get predefined token total issuance at specified block height/hash.
It integrates koa.js as the backend server, and you can find the code under packages/backend
folder.
The server provides apis for spaces, balances and proposals, check them
under packages/backend/features
folder.
It depends on MongoDB and related proposal and votes data are stored. All votes data are signed with polkadot keys and uploaded to IPFS too. We use decoo as the IPFS service provider, so make sure to register an account and get the corresponding decoo api token and secret key.
This package also depends on the node-api package to fetch on-chain info.
So don't forget to config the required NODE_API_ENDPOINT
environment variable.
Generally, Its features include:
- Providing restful apis for next page.
- Managing business data with MongoDB.
- Querying chain data from
node-api
package.
Next package depends on next.js and renders the fronted pages.
Make sure mongodb is installed, while corresponding url is required to config in the next package. Check here to find a way to install it natively, or run it with docker:
docker run -d --name mongo -p 27017:27017 mongo:4.4.2
You may need more configuration for production environment.
Register an decoo account and get the api key and secret. Or for your convenience, just use following test key.
DECOO_API_SECRET_KEY=MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJxxBVD13g3ah0E5OYS13yJ5UbON9cn9Q5dnCEM/T7opfClOGYeG/dH+8uoNEweCcTBkueU+sLtFAYRMThihmT8VolFvbEtI0rrdXClAqzjxoQwN5DPOyGKs2ngDjG6I8Ar5y0BIYdoHNvoU0k0PzefGT51LwnNZoVDMODpkKdjnAgMBAAECgYBCbge44j6hmVr3yknvXZ9brzKPUUe+tundv6WVkKvVPEp5660RjLP5WQ5jbpvXA3/28b6yZtV7IAlN2W0MLoq4wS/0Il0h1Kha5G6T6WI/SgD2bfC0AsuCBU5lA9iMCgoidfBE+6BjlJDH7QSsNI3LQWwxUQ7osN58p1k9i4egmQJBAN1Q0sBx2SgZjifwlSVA13iESrs0xe/Pagf5S9cuRUnHZs+9v7ZJXuOmJ7Ple7vstuMTMWqWtUWV3st1psdMbbMCQQC09XJDCyZD6soIVgWkV30rSUGRUf65QHC2K4HLtVdpSes1L6GiCxgxyxV/I24o8p/5JN11MMR5QpRc5go1d1X9AkEAxMZ9/Dm9mNfP+1b/ZRYX/sGxKG4tp6FFZz2S3wn29ThkA0V01YC667HqDxt1PoujuJZyE5FYLzyn0UMUPJOJ3QJBAJC83UaYrWOXcT8Xpu2a+MfdkS8t2ULNMxnSVL/d7OuPLy1cSrj0jMaO/EOz0BG6do/tl6B7gDrJMSfY64N2TvUCQQCzJDnyA38Fz9fo2htWp6cKzA4pNrHBpRtYVaLXp4Sc56JcN3SMS6f3E4n7rFLIZmvjW1MryiGN8fVzTgqQAmN4
DECOO_API_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOnsiYXBpX2tleSI6IjExNThLQmZ3N1pmQ3pGdFd1NEFNaXRHRU9YYUxNMlZpN2Q1TzE2MzcxMzU2ODgyMDkiLCJ1c2VyX2lkIjoxMTU4fX0.tKeVjP4CxyVeZn8Y1OPzR177noAWzqgoWBXLnup1Y7Y
yarn
cd packages/node-api
cat .env.example > .env
The default environment variables will work, but if you want to change some, just edit the '.env' file.
# You can change the chain endpoints, separated by ';'.
DOT_ENDPOINTS=wss://rpc.polkadot.io;wss://polkadot.api.onfinality.io/public-ws;wss://polkadot-rpc.dwellir.com
KSM_ENDPOINTS=wss://kusama-rpc.polkadot.io;wss://kusama.api.onfinality.io/public-ws;wss://kusama-rpc.dwellir.com
KAR_ENDPOINTS=wss://karura.api.onfinality.io/public-ws;wss://karura-rpc-0.aca-api.network;wss://karura-rpc-1.aca-api.network;wss://karura-rpc-2.aca-api.network/ws;wss://karura-rpc-3.aca-api.network/ws;wss://karura.polkawallet.io
KHA_ENDPOINTS=wss://khala.api.onfinality.io/public-ws
STATEMINE_ENDPOINTS=wss://statemine.api.onfinality.io/public-ws;wss://statemine-rpc.polkadot.io
BNC_ENDPOINTS=wss://bifrost-parachain.api.onfinality.io/public-ws;wss://bifrost-rpc.liebi.com/ws;wss://us.bifrost-rpc.liebi.com/ws;wss://eu.bifrost-rpc.liebi.com/ws
KINT_ENDPOINTS=wss://kintsugi.api.onfinality.io/public-ws;wss://api-kusama.interlay.io/parachain
INTR_ENDPOINTS=wss://interlay.api.onfinality.io/public-ws;wss://api.interlay.io/parachain
# You need a infura key to call the ethereum rpcs
INFURA_KEY=xxx
# Alchemy.com api key. Optional, there will be no alchemy nodes if not set
ALCHEMY_KEY=xxx
SERVER_PORT=3223 # keep it
Then run
node src/index.js
Well, the node-api should be ready.
3. Run backend for the restful api server
Come back to the project root dir and run
cd packages/backend
cat .env.example > .env
Open the '.env' file and do necessary configuration
PORT=8081 # keep it, it will be the resutful api server port
MONGO_URL=mongodb://localhost:27017 # set your mongodb url
MONGO_DB_NAME=voting # keep it or change it to any name you like
DECOO_API_OAUTH_ENDPOINT=https://api.decoo.io
DECOO_API_UPLOAD_ENDPOINT=https://api-hk.decoo.io
DECOO_IPFS_ENDPOINT=https://ipfs-hk.decoo.io/ipfs/
DECOO_API_TOKEN=xxx # fill the decoo jwt token
DECOO_API_SECRET_KEY=xxx # fill the decoo verification key
TEST_ACCOUNTS=xxx|yyy # ignore it, for test
TEST_ACCOUNT_BALANCE=100000000000 # ignore it, for test
# The node api server url. Do not append '/' to the end.
NODE_API_ENDPOINT=http://localhost:3223
Run following scripts to initialize the spaces in database
cd packages/backend && node src/scripts/init-spaces.js
Then run
yarn run dev
or
node server.js
The restful api server will be ready.
Come back to the project root dir and run
cd packages/next
cat .env.example > .env
Open the '.env' file and do necessary configuration
PORT=8001
NEXT_PUBLIC_API_END_POINT=http://127.0.0.1:8001/
NEXT_PUBLIC_BACKEND_API_END_POINT=http://127.0.0.1:8081/
NEXT_PUBLIC_IDENTITY_SERVER_HOST=https://id.statescan.io
Then run
yarn run dev
or
node server.js
Do everything work well? Join OpenSquare matrix room if any problems.