Ergo 101 : Side tooling for building dApps on Ergo
Getting a full fleshed working dApp on Ergo requires more than just A smart contract (Ergoscript) and Blockchain transactions. For example dApps need to react to events happening on the blockchain. In this entry I will introduce some of the tooling that the community has built which can help you ship your Ergo dApps.
Testing : CI/CD
Testing your contracts on chain (either on Testnet or Mainnet) can be very time consuming. Knowing how to test your contracts quickly is something I and other community members struggled with. Why? if you are testing on-chain you have to wait for transactions to be mined, you need to talk to a node, you need a running node. Ideally you should be able to unit tests your contracts so you can iterate very quickly in your dApp development. The cycle: make changes, run unit-tests, check output should be as fast as possible.
Anon-real’s testing samples:
Anon-real is one contributor in Ergo that you MUST follow!. In one of the Hackathons anon shared the way in which he/she tests contracts using app-kit. You can go over the details in the shared Github repo. The main point is: you can test by creating Transactions and signing them, if contract evaluates to false the signing will fail , that fail mechanism can be used to test your contracts as you can see in anon-real’s examples.
Ergo-puppet (Playground and testing framework)
The ergo playground is an amazing tool for getting started with Ergoscript. However there are some issues. The playground does not use the latest version of app-kit, therefore you will notice some differences in how you structure your transactions when you start building your actual dApp.
Ergo-puppet is an updated playground which you can use to run blockchain simulations just like you do on the original ergo playground. The way in which you structure the transactions are the same as you would do in your ergo dApp if you are using app-kit.
However Ergo-puppet can also be used for unit-testing, in fact, we have used it to test ergonames’ contracts (see tests here) . Ergo-puppet provides a dummy blockchain and a simulated context in which you can mock the state of the blockchain at a particular point in time. Ergonames repo is setup just like any regular software project where unit-tests are automatically run on github actions.
Reacting to on chain events
Once you are done writing your contracts you will start architecting your dApp. Most (if not all dApps) need to react to on-chain events. For example,
- your app might need to make a transaction if someone send some assets to a particular contract.
- Perhaps you might want to mint an NFT when a particular amount of ERG was sent to a contract.
- maybe you want to send a push notification to a user when a particular transaction occurs.
All of these scenarios requires to keep a watch on the blockchain and then do some following action. This is a common use case
Ergo-Assembler
Ergo assembler is a project used in the ergo auction house. I won’t go into details but before the nautilus wallet came around dApps had the problem of “how to get user’s funds?”. The ergo-assembler is a server that you can ask to wait for a particular transaction to happen, and when it happens ask it to trigger another transaction.
In the ergo auction house a user can mint NFTs, in order to do that, it needs to send funds to a particular address that the website points to. For that the user needs to go to his/her wallet and do the transaction.
What happens behind doors is that the frontend of ergo auction house sends a requests to its ergo-assembler server, telling it “I expect a user to send some funds to this specific address if those funds arrive in a tx then mint an NFT”.
This work around let ergo auction house operate even before we had proper wallets. Ergo assembler also takes care of timing out a tx and/or refunding boxes if for example the user sent a wrong amount.
You can see the details on how ergo assembler is used if you check the source code of the ergo auction house.
If you want more context: you can also see assembler’s original motivation and explanation in ergoforum
Scanner
The scanner is a server that can track unspent boxes under a particular address. You can tell the scanner:
“ I want to set a tracker for unspent boxes under this contract XXX”
other services can then ping the scanner server asking for a list of boxes under a particular tracker. You can set multiple trackers.
Every ~60 seconds the scanner server talks to an ErgoNode to fetch blockchain headers in order to update its internal state. This project uses Akka so it is highly scalable.
Oura (Cardano only, but maybe Ergo in the future)
Oura is a very very interesting project made by the Cardano community. Ergo and Cardano are both built on top of the eUTXO paradigm so there is an overlap of similar problems .
Oura is a general pipeline tool that can listen to any event in the cardano blockchain and trigger events in other systems. For example you can easily tell Oura to call an AWS lambda function when a particular TX happens or when a particular UTXO box gets used. Some of the systems that you can integrate with are: Kafka, AWS kinesis, AWS lambda..
Even though currently Oura does not support Ergo, I don’t see a reason why it could not be integrated as the major pieces for supporting Ergo already exists within Oura. In fact Oura’s author Santiago Carmuega has mentioned that long term wise other blockchains could be integrated.
Wrapping things up:
Building a dApp is more than writing smart contracts.
As the ergo community grows we will see better tooling to ship dApps faster. In this post I try to document some of the useful ones that I bumped into.
If you think I miss one feel free to share it on the comments, you can also give me a poke on twitter @dav009 :)