Last year I started working on Alan.dart, a pure Dart library that allows to create, sign and send transaction to any blockchain of the Cosmos ecosystem. This was possible thanks to the first ICF grant I received, which allowed me to update the library to be compatible with Cosmos v0.39 and add the support for the staking and governance modules.
Lately, however, things have changed radically inside the Cosmos ecosystem. Stargate was released, and with it a lot of new features such as
- the support for Protobuf;
- a change in how transactions can be signed;
- the support for gRPC;
- and many many more
Since I believe that Alan.dart currently represents the only library that allows developers to easily build an iOS and Android application that interacts with a Cosmos chain, I then asked the ICF for a second grant to update the library to be compatible with all those changes. Following, you can find what I have been working on and what those changes mean for Alan.dart itself.
Protobuf support 📜
The fist and most important change is in how messages classes are now created.
Before Cosmos supported Protobuf, all messages classes inside Alan.dart should have implemented the
StdMsg interface. This was later used to properly serialize the message using Amino, a custom encoding algorithm that was created for Cosmos itself.
Later, however, the Cosmos SDK has replaced Amino with the much more efficient Protobuf. This allows all client libraries to generate the implementation of different messages classes using the Protobuf compiler.
What it means for developers using Alan.dart is that they no longer have to re-implement custom classes to represent chain messages, but they can simply generate those classes using the instructions provided on the Alan.dart documentation website. This makes it even faster to code with Alan.dart! 🚀
Transaction serialization and signing ✍️
Another big change inside Cosmos v0.40 is the addition of the new method that clients can use while signing transactions.
Before Stargate, Cosmos transactions should have been serialized using Amino, and then they should have been signed. However, due to the fact that Amino did not have a standard implementation for all programming languages, this meant that we library developers had to write our own implementation by hand. This resulted in possibly slow and non-efficient implementation, which meant slower signing times that lead to slower applications.
Starting with Cosmos v0.40, however, it is now possible to sign transactions after serializing them with Protobuf. Since Protobuf already has a standard implementation for most programming languages, and it is much faster than Amino, this results in signing times being 10 times faster! ✈️
gRPC support 🌐
Finally, the last important change that Stargate has bough for client developers is the support to gRPC clients.
Before v0.40, Cosmos only supported querying the chain state using classic REST APIs endpoints that returned JSON-encoded data. This method, however, resulted in poor performance from a client perspective because it meant that the application should have de-serialized the JSON object before using it.
With gRPC, instead, data is now returned from the chain already encoded as a byte array, which is much smaller than a JSON file, and is read by the library without any de-serialization needed. This makes it faster and more efficient to query any kind of data! 🏎️
Thanks to this update, it should be even easier to create Dart of Flutter applications that interact with a Cosmos chain. Also, it should make already existing applications run faster and more efficiently even on mobile devices that were struggling before.
If you have any question, feel free to ask them inside the Discord channel of the Cosmos.network server 💬
“If I have seen further, it is by standing on the shoulders of giants.” — Isaac Newton