Cowchain Farm combines Rust-based smart contracts built with Soroban on Stellar blockchain, and a web app client to access the smart contracts functionality built with one of the most popular cross-platform frameworks, Flutter.
Cowchain Farm smart contract will cover several capabilities of Soroban that exist in the Preview 11 release, which include:
- Authentication and authorization
- Error handling
- Custom types
- Contract initialization
- Contract upgrading
- Payment transfer
- Data storage expiration
- Events
While the Cowchain Farm web app will cover the following:
- Calling Soroban smart contract function using Flutter Stellar SDK
- Communication with the Freighter browser extension
And the latest addition is the Cowchain Farm notification service, which includes:
- Ingesting events from Soroban smart contracts using Dart CLI with Flutter Stellar SDK
- Sending notifications to Cowchain Farm users using OneSignal
This article is specifically about the Dart CLI notification service for Cowchain Farm.
Discussion for Cowchain Farm smart contract is in the Cowchain Farm Soroban repository, and the discussion for Cowchain Farm web app is in the Cowchain Farm App repository.
The Cowchain Farm Dart CLI in this repository was developed using Dart version 3.1.2
Before running the Cowchain Farm Dart CLI, there are several things we need first, including:
- OneSignal App ID
- OneSignal Rest API Key
- OneSignal Android Notification Channel ID
- Soroban smart contract Address (contract that we will listen to)
- Stellar account Secret Key (for invoking smart contract function)
- Clone the repository:
git clone https://github.com/hasToDev/cowchain-farm-alert.git
- Install all the project dependencies:
dart pub get
- Run on local machine:
dart run bin/cowchain_farm_alert.dart --soroban \ --app-id <OneSignal App ID> \ --restapi-key <OneSignal Rest API Key> \ --channel-id-android <OneSignal Android Notification Channel ID> \ --notification-color <color in ARGB format, e.g. FFFFAC45 \ --soroban-contract-address <Soroban smart contract address> \ --stellar-seed <Stellar account secret key for invoking smart contract> \ --interval <check Soroban event every X second, e.g 60>
- Build on local machine:
dart compile exe bin/cowchain_farm_alert.dart
Dart is known for its limitation, which is No cross-compilation support.
It means the compiler can create machine code only for the operating system you’re compiling. You need to run the compiler three times on three different machines to create executables for macOS, Windows, and Linux.
To overcome this limitation, we use a continuous integration (CI) provider that supports all three operating systems, Codemagic. You can also follow this articles to learn how to Cross-compiling Dart CLI applications with Codemagic.
For the Cowchain Farm notification service, we choose to deploy the Dart CLI inside a Docker container in a cloud server that runs Ubuntu.
The following are the files used to carry out the deployment apart from the compiled Dart CLI:
- Dockerfile
FROM alpine:latest LABEL maintainer="hasToDev" RUN apk add libc6-compat RUN mkdir /app WORKDIR /app COPY . . ENV PORT 8080 RUN chmod +x /app/cowchain CMD ["/app/cowchain", \ "--soroban", \ "--app-id=xxxx-xxxx-xxxx-xxxx", \ "--restapi-key=xxxx", \ "--channel-id-android=xxxx-xxxx-xxxx-xxxx", \ "--notification-color=FFFFAC45", \ "--soroban-contract-address=CAV...HXJ", \ "--stellar-seed=SY6...WQZ", \ "--interval=60" \ ]
- compose.yaml
version: '3.7' services: cowapp: container_name: cowapp_dev restart: always build: . image: cowapp networks: - soroban_net volumes: - soroban_vol:/app/ ports: - 80:8080 networks: soroban_net: external: true volumes: soroban_vol: external: true
This CLI will listen to events emitted by Cowchain Farm smart contracts. Then, this event will be processed according to its type.
This CLI will send notifications when your cow starts to feel hungry, when you win an auction, or when your funds are refunded because someone outbid you at an auction.
So that you can receive notifications provided by the CLI, you must install the Cowchain Farm notification app on your mobile phone, which you can download at this link.
You can also clone the repository for Cowchain Farm notification app at Cowchain Farm App repository, and build the app by yourself. Currently, the app only supports Android mobile phones.
After installing, register the account ID or public key of the Stellar account you use to play Cowchain Farm. Once registered, notifications sent by CLI will reach you on your phone.
The Cowchain Farm is distributed under an MIT license. See the LICENSE for more information.