Set up your environment
The first step to build with ComposeDB is setting up your development environment. This guide will show you how to install and configure relevant packages and tools.
Installation
Create your project directory
Start with creating the project directory. Here you’ll store all your app’s local files:
mkdir my-project #creates a new directory
cd my-project #targets the created directory
Node.js
If you don’t already have them installed, you will need to install Node.js v16 and a package manager. We primarily use pnpm
, but npm
and yarn
are supported as well.
Use this command to make sure you have the correct versions installed.
node -v
pnpm -v
Ceramic
ComposeDB runs on Ceramic, so you will need to run a Ceramic node. To get started, we recommend running a local Ceramic node. If you're interested in running the production node, you can follow the tutorial here.
The Ceramic CLI provides a set of commands that make it easier to run and manage Ceramic nodes. We will start by installing the Ceramic CLI:
- npm
- pnpm
- yarn
npm install --location=global @ceramicnetwork/cli
pnpm install -g @ceramicnetwork/cli
Global packages are only supported for yarn 2.x and older. For yarn 3.x and newer, use yarn dlx
to run composedb cli commands
yarn global add @ceramicnetwork/cli
ComposeDB
Next install the ComposeDB CLI, which enables you to interact with ComposeDB data from your terminal. Install ComposeDB CLI using the following command:
- npm
- pnpm
- yarn
npm install --location=global @composedb/cli
pnpm add -g @composedb/cli
Global packages are only supported for yarn 2.x and older. For yarn 3.x and newer, use yarn dlx
to run composedb cli commands
yarn global add @composedb/cli
ComposeDB provides two additional libraries that support development:
- @composedb/devtools containing utilities related to managing composites
- @composedb/devtools-node which contains utilities for interacting with the local file system and starting a local HTTP server.
To install the development packages, run:
- npm
- pnpm
- yarn
npm install -D @composedb/devtools @composedb/devtools-node
pnpm add -D @composedb/devtools @composedb/devtools-node
yarn add -D @composedb/devtools @composedb/devtools-node
Setup
Run a Ceramic node
You can check that everything was installed correctly by spinning up a Ceramic node. Running the command below will start the Ceramic node in local mode and connect to Clay testnet. Indexing is a key component of ComposeDB, which syncs data across nodes. Enable indexing by toggling:
- npm
- pnpm
- yarn
npx @ceramicnetwork/cli daemon
pnpm dlx @ceramicnetwork/cli daemon
yarn dlx @ceramicnetwork/cli daemon
If you see the following output in your terminal, that means you have successfully started a local node and connected to Clay testnet 🚀
IMPORTANT: Ceramic API running on 0.0.0.0:7007'
After you start a node, a node configuration file is created. Later in this guide, you’ll be editing this file. You can find it at the following path: ~/.ceramic/daemon.config.json
Developer Account
Generate your private key
You will need a private key for authorizing ComposeDB CLI commands in the later stages of development. You can generate it using the command below. Save it for later use:
composedb did:generate-private-key
Important: Store your private key securely - the key allows changes to be made to you app. In addition, you will need it throughout the app development process.
Generate your account
Indexing is one of the key features of ComposeDB. In order to notify the Ceramic node which models have to be indexed, the ComposeDB tools have to interact with the restricted Admin API. Calling the API requires an authenticated Decentralized Identifier (DID) to be provided in the node configuration file. Create a DID by running the following command, using the private key generated previously:
composedb did:from-private-key your-private-key
⚠️ Copy this authenticated DID key and store it in a secure place, just like with your private key above. This DID key will have to be provided in your Ceramic node’s configuration file which will ensure that only authorized users can make changes to your application, e.g. deploy models on your Ceramic node.
Using your account
Provide the authenticated DID by opening the node configuration file which defaults to ~/.ceramic/daemon.config.json
and specifying it in the admin-dids
section of the file as shown below:
{
...
"http-api": {
...
"admin-dids": ["did:key:..."]
},
"indexing": {
...
"allow-queries-before-historical-sync": true
}
}
Save this file. By this point you should have your development environment and all configurations in place to get started working on your application.
Confirmation
As a final test, spin up the Ceramic local node:
ceramic daemon --network=testnet-clay
Once again, you should see your local Ceramic node up and running as follows:
IMPORTANT: Ceramic API running on 0.0.0.0:7007'
Next steps
After setting up your environment, the next step is to Create your composite →