Smart contracts and JS API for Kosmos Kredits
Go to file
Râu Cao a2ebc609ea
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-29 15:03:03 +02:00
.ganache-db Add empty Ganache DB directory 2018-04-17 13:13:52 +02:00
.gitea Add release drafter action configs 2023-04-11 23:13:05 +02:00
.github Add release-drafter config 2019-09-18 12:49:00 +02:00
.openzeppelin Upgrade testnet contribution contract, reinit contributor contract 2023-08-07 23:05:38 +02:00
config Pre-confirm some contributions and reimbursements on bootstrap 2023-08-24 16:43:52 +02:00
contracts Update reimbursement to support migration 2023-08-24 15:45:28 +02:00
deployments/rinkeby Deployment details 2021-02-19 10:24:54 +01:00
docs readme 2019-03-24 11:01:59 +01:00
lib 7.4.0 2023-08-29 15:03:03 +02:00
scripts Add support to start the contribution import from a specific id 2023-08-13 14:46:48 +02:00
test/contracts Resolve some solhint errors and warnings 2023-08-07 23:05:15 +02:00
.dockerignore Add Docker image configs 2022-08-08 18:20:38 +02:00
.drone.yml CI 2022-08-23 10:55:35 +01:00
.eslintignore Add mocha, chai, and test for Contribution 2022-08-23 10:42:07 +01:00
.eslintrc.js Contributor app tests (#143) 2019-07-22 06:55:22 +00:00
.gitignore Merge branch 'master' into new-final-deploy 2023-08-07 22:07:45 +02:00
.nvmrc Recommend node.js 16 via nvm config 2022-05-16 19:07:29 +02:00
.solhint.json Resolve some solhint errors and warnings 2023-08-07 23:05:15 +02:00
Dockerfile Add Docker image configs 2022-08-08 18:20:38 +02:00
hardhat.config.js "Fix" default network name in hardhat config 2023-08-24 14:52:38 +02:00
package-lock.json 7.4.0 2023-08-29 15:03:03 +02:00
package.json 7.4.0 2023-08-29 15:03:03 +02:00 Update README 2023-03-22 18:14:12 +07:00
truffle.js Fix provider fallbacks for non dev networks 2019-04-05 13:51:23 +02:00

npm Build Status

Kredits Contracts

This repository contains the Solidity smart contracts and the JavaScript API wrapper for Kosmos Kredits.



App dependencies

All requirements are defined in package.json.

$ npm install

Local development chain

We use hardhat as development environment for the smart contracts.

To run a local development chain run:

$ npm run devchain # or: hardhat node --network hardhat


  1. Run an EVM node and ipfs

     $ npm run devchain
     $ ipfs daemon
  2. Compile contracts and build ABIs

     (compiled artifacts will be in `/artifacts`)
     $ npm run build
  3. Deploy new upgradable contract proxies

     $ npm run deploy:dao
  4. Execute seeds to create demo contributors, contributions, etc. (optional)

     $ npm run seeds

Step 2-4 is also summarized in npm run bootstrap

  1. Show contract addresses

     $ cat lib/addresses.json

Fund a local development account

If you need to fund development accounts with devchain coins:

$ npm run fund # or hardhat fund --network localhost

Specs / Testing

With a local development chain running:

$ hardhat test

If you add or change contract code, please make sure to add and/or adapt tests accordingly. Don't worry, it's easy! You can use existing tests as a template for new ones.

Contract architecture

We use the OpenZeppelin hardhat proxy for deploying and managing upgradeable contracts. (see scripts/create-proxy.js)

Each contract is independent and is connected to its dependencies by storing the addresses of the other contracts.

Helper scripts

scripts/ contains some helper scripts to interact with the contracts from the CLI. At some point these should be moved into a real nice CLI.

To run these scripts use hardhat run. For example: hardhat run scripts/list-contributors.js --network localhost. (NOTE: add --network localhost or the network you want to use)

Some scripts are also defined as npm script, see package.json.


Similar to cli.js but only provides a REPL with an initialized kredits instance.

$ hardhat console --network localhost

add-{contributor, contribution, proposal}.js

Script to add a new entries to the contracts using the JS wrapper

$ hardhat run scripts/add-{contributor, contribution, proposal}.js --network localhost

list-{contributors, contributions, proposals}.js

List contract entries

$ hardhat run scripts/list-{contributors, contributions, proposals}.js --network localhost


Run seeds defined in config/seeds.js.

$ npm run seeds

Get the contract addresses

All contract addresses are stored in lib/addresses.json

$ cat lib/addresses.json

Upgradeable contracts

We use OpenZeppelin for an upgradeable contracts:

Refer to the OpenZeppelin README and scripts/create-proxy.js

OpenZeppelin Step by Step guide

For an upgrade example checkout scripts/upgrade-example.js

Deployment to other networks

Deployable networks are configured in the hardhat.config.js.

To deploy to those networks provide the --network argument to the hardhat commands, e.g. --network rsk.

Please note that some npm scripts combine multiple hardhat commands. In those cases the hardhat commands needs to be run manually with the --network argument. (=> don't use npm run bootstrap)

Set a DEPLOY_KEY environment variable with the private key (HEX) which will be used as a root/deploy account

Typical deployment flow:

$ npm run build
$ hardhat run scripts/create-proxy.js --network rsk
# OR with deploy key:
$ DEPLOY_KEY=0xsomething hardhat run scripts/create-proxy.js --network rsk
$ # commit the new addresses in the addresses.json file if needed

To run the console on one of the non localhost networks you can also just pass on the --network argument.

$ hardhat console --network rsk