Cambiatus Wiki and Documentation
Cambiatus is a DApp (decentralized application) that leverages the EOS blockchain protocol. Here are a few resources to checkout if you are new to DApp, What is a Dapp, A Dapp is not a protocol. Even though blockchain brings many benefits to an applicaiton it also has its limitations. The major limitation of blockchain is the ability to query and fetch data in a timely manner. In order to over come this limitation we took a hybrid approach: we store all data on the blockchain and replicate partial data on a traditional database. With this approach we gain the benefits of blockchain - security and immutability of our data - and the benefits of traditional databases - efficient and user friendly retrieval of data.
Here is an overview of the architecutre. We’ll go more into detail in the next section.
In this section we’ll explore how our data flows through our application. Here are the objectives for this section:
When learning a new concept it’s always great to use aexamples, so we’ll walkthrough two use cases:
Our frontend is a static application built using Elm; the frontend sends transactions and triggers actions on the blockchain using eosjs library.
Here is a great explaintation of what action and transcation mean in context of EOS:
“An action is a unit of code to be executed inside a transaction. A transaction is a set of one or more actions which will execute or fail completely.” source
Let’s say we want to create a new community identified by the symbol 0,TST
. In order to do so we need to do the following steps:
create
community action
A transaction has the following structure
{
account: "cambiatus.cm",
name: "create",
authorization: [{ actor: "janedoe", permission: "active" }],
data: {
cmm_asset: "0 TST",
creator: "janedoe12334",
name: "TESTCOM",
description: "A test community"
}
}
cambiatus.cm
or cambiatus.tk
, depending on if your transaction is related to a community (.cm) or a token (.tk).ACTION
defined by our community and token contracts.The code that sends the action to the blockchain can be found here
Click on the website below and click on the contract
tab to see what actions and datas are available for cambiatus.cm
or cambiatus.tk
.
Once the transaction has been pushed to the blockchain then it would get verified and added to the blockchain. The diagram below demonstrates the process of adding a block to EOS blockchain.
The new community has been added to the blockchain! However, we sill need to send the data to our database so our frontend could fetch and display it to the user. We can accompolish this by leveraging an event driven library developed by EOS called demux-js.
Action Reader
listens for any changes in blockchain. When it detects a change it will pass the data to the Action Watcher
.Action Watcher
triggers the Action Handler
, which in turn updates our database with the data retrieved from the blockchain.Once an action has been pushed to the blockchain, we optimistically assume that data has trickled down to our database. The current method is very unreliable for querying for the data; however, we are looking to leverage Graphql subscription for this see here.
The process for updating a community is similar to creating a new community the only difference is how we react once we have pushed the transaction to the blockchain.
After we push a transaction, on a successful operation we receive a transactionId
, which indicates that our data has been added to the blockchain.
Or our transaction can fail. It can fail for two reasons: