ATTN: ComposeDB is currently in active development and composites CANNOT be deployed on mainnet!
What does this workshop cover:
- Setup Ceramic node incl. ComposeDB developer preview with relations support
- Create and deploy your first composites
- Add and query data
- ✨Ceramic Magic ✨
Oh and btw... we'd ❤️ to hear your feedback - ping us on Discord or submit directly through our FORUM
So, lets get started! 🚀
Install the necessities - @next
ensures you are running the latest developer preview:
pnpm install --global @composedb/cli@next @ceramicnetwork/cli@next
Now to create a new PK & corresponding DID to get our node setup.
composedb did:generate-private-key
composedb did:from-private-key ADD_GENERATED_PK_HERE
For demo purposes and to follow along with the tutorial you can store the PK in priv.key
. Just be careful NOT TO COMMIT this file by accident. Alternatively, you can also set a new ENV variable DID_PRIVATE_KEY
. Doing this you can just omit --did-private-key
from the example commands.
ATTN: ALWAYS keep your private key safe and copy the DID into the node config file located under
~/.ceramic/daemon.config.json
which will prepare the node for future CLI interactions. If you don't have a config file in your directory yet, simply start the node once viaceramic daemon
and exit again. This will create a default config file:
Node config example:
{
"anchor": {},
"http-api": {
"cors-allowed-origins": [
".*"
],
"admin-dids": ["did:key:INSERT_DID_KEY_HERE"]
},
"ipfs": {
"mode": "bundled"
},
"logger": {
"log-level": 2,
"log-to-files": false
},
"metrics": {
"metrics-exporter-enabled": false,
"metrics-port": 9090
},
"network": {
"name": "testnet-clay"
},
"node": {},
"state-store": {
"mode": "fs",
"local-directory": "/Users/Ceramic/.ceramic/statestore/"
},
"indexing": {
"db": "sqlite:///Users/Ceramic/.ceramic/indexing.sqlite",
"allow-queries-before-historical-sync": true,
"models": []
}
}
After adding the DID, lets start the node and on to the build steps:
export CERAMIC_ENABLE_EXPERIMENTAL_COMPOSE_DB="true"; ceramic daemon
Ensure the Cearmic Daemon is running and proper indexing environment variables are set export CERAMIC_ENABLE_EXPERIMENTAL_COMPOSE_DB=true WARNING: if you have previous models indexed that you don’t care about anymore you’ll need to remove the sqlite file if you no longer want Ceramic to index them. The daemon will not start if they exist in the database but are not referenced in the config.
- Create or edit
AddressBook.graphql
schema - Create a composite from the AddressBook schema:
composedb composite:create schemas/AddressBook.graphql --output eth-address-book.json --did-private-key $(cat priv.key)
- Get the created
AddressBook
ID to reference it in the relational schema:
composedb composite:models eth-address-book.json
Copy out ID to use in the next step:
✔ Fetching composite's models... Done!
[{"id":"kjzl6hvfrbw6c8q2qtmt297gpp66meihwthrcg3uiohzxhv5myz5d7ajf30ylgz","name":"AddressBook","description":"Simple Address Book"}]
- Create or edit
AddressBookEntry.graqhql
schema and use the correct ID from the previous step to referenceAddressBook
:
composedb composite:create schemas/AddressBookEntry.graphql --output=eth-address-book-entries.json --did-private-key $(cat priv.key)
- Merge the composites into a single encoded file:
composedb composite:merge eth-address-book.json eth-address-book-entries.json --output=demo-address-book-merged.json
- Deploy the merged composite. This will add the models to your local node and start indexing automatically:
composedb composite:deploy demo-address-book-merged.json
Still with me... great! We are ready to play with data! 🙌
If you made it this far, I'm proud of you! Now comes the really fun part:
-
Compile a runtime representation to use (this would be used by our application to interact with the node):
composedb composite:compile demo-address-book-merged.json demo-runtime.json
-
In lieu of a front-end, ComposeDB ships with GraphiQL to get you started:
composedb graphql:server --graphiql --port=35000 demo-runtime.json --did-private-key=$(cat priv.key)
You should be able to CONNECT now!
query{
addressBookIndex(first:10) {
edges{
node{
id
addressBookName
}}
}
}
Since we don't have data nothing will be returned, but if you don't get an error you are ready to go!
mutation CreateNewAddressBook($i: CreateAddressBookInput!) {
createAddressBook(input: $i) {
document {
id
addressBookName
}
}
}
Query Variables:
{
"i": {
"content": {
"addressBookName": "PL Summit"
}
}
}
mutation CreateNewAddressBookEntry ($i: CreateAddressBookEntryInput!) {
createAddressBookEntry(input: $i) {
document {
id
entryName
walletAddresses {
address
blockchainNetwork
}
}
}
}
Query Variables:
{
"i": {
"content": {
"addressBook": "INSERT CREATED ADDRESS BOOK ID HERE",
"entryName": "my fantastic entry",
"walletAddresses": {
"address": "0x00",
"blockchainNetwork": "ethereum"
}
}
}
}
query {
addressBookEntryIndex(first: 5) {
edges{
node {
book {
id
addressBookName
}
entryName
walletAddresses {
address
blockchainNetwork
}
}
}
}
}
And that's all folks 😎 ! You are now officialy a ComposeDB PRO. Go back and have a look at the schemas and play around with them or try to create your own schemas and models. Can't wait to see what you are building on ComposeDB!
- We are HIRING!
- Start a deep dive with the COMPOSE DB DOCS
- Recap VIDEO that walks you through step by step
WARNING: not a 100% match to the above & might be a bit outdated but captures the gist of the demo
- Come and join our COMMUNITY FORUM
- Node deployment TEMPLATE (EXPERIMENTAL!!!)