Skip to content

dorucioclea/stacks-dev-env

Repository files navigation

Logo

dev-environment

Custom badge Maintained

Stacks local development environment for clarity contracts
Development environment for Stacks smart contracts with support for unit tests and integration tests


-----------------------------------------------------

➤ Table of Contents

-----------------------------------------------------

➤ Local testnet

The docker folder contains a docker-compose configuration to run a local testnet Stacks blockchain environment from scratch

This starts the following private testnet components:

  • Postgres database
  • Bitcoin - puppet chain
  • Stacks node
  • Stacks api
  • Local stacks blockchain explorer

It contains two docker-compose files:

  • bns.yaml
  • docker-compose.yaml

If you want to import BNS data you should run

$> docker-compose -f bns.yaml pull
$> docker-compose -f bns.yaml build
$> docker-compose -f bns.yaml up

This will import bns data into the /bns-data folder.

Moving forward, starting the stack:

$> docker-compose pull
$> docker-compose build
$> docker-compose up

Note:

If you do not want to import bns data, then you will need to comment out the environment line BNS_IMPORT_DIR: /bns-data from the stacks-blockchain-api container, otherwise the container will panic if it doesn't find the files

If you did import the bns data, you need to uncomment (if previously commented out) the environment line above and be aware that the stacks-blockchain will experience Connection refused problems from stacks-blockchain-api for the duration of bns data import. After the import, the API will become ready and accept events from stacks-blockchain node

-----------------------------------------------------

➤ Getting started

When getting started with developing smart contracts, you need to first install the packages by calling

./install.sh

This installs a certain version of clarity-cli we're using to interact with the smart contracts locally in unit-test mode

-----------------------------------------------------

➤ Development of smart contracts

The contracts folder contains some example smart contracts already included.

When developing/updating a new smart contract you need to generate:

  • Abi json file
  • Typescript interface file
  • Index file exposing a neat and simple way of accessing the smart contract interface

You can do all that by running:

yarn generate

-----------------------------------------------------

➤ Unit tests

When writing unit tests you can use the examples included in /test/counter.test.ts

-----------------------------------------------------

➤ Integration tests

When writing integration tests you can use the example included in /test/integration.test.ts

The way we run it is:

First, start the local testnet by doing

$> cd docker && docker-compose up

Wait until the local testnet is fully started and then execute the integration test

$> yarn integration

-----------------------------------------------------

➤ Contributors

Doru Cioclea Octavian You?
Doru Cioclea Octavian You?
🔥

-----------------------------------------------------

➤ License

Licensed under ISC.