In this article, I will explain the latest upgrade of Cowchain Farm with Soroban Preview 11 on Stellar Testnet.
For the Stellar Futurenet version of Cowchain Farm, you can check out my previous post here.
Quick Recap
Cowchain Farm is an idle game concept based on a smart contract app built using Soroban on Stellar blockchain and Flutter as the front-end framework.
You can Buy, Feed, and Sell your cow in the app. The cow price will be increased if you feed them on time.
What's New on TestNET
The latest upgrade for Cowchain Farm brings several new exciting features that will benefit the user greatly. These features include:
- Random Gender
- Unique Name
- Auctions
- Notification Service
Also, on this upgrade, Cowchain Farm will start emitting soroban events for every crucial function related to the user.
Now, let's dig into those new features one by one.
Random Gender
Soroban Preview 11 brings PRNG to the field.
PRNGs are very useful for creating random generators. Therefore, on this upgrade, the Cowchain Farm utilizes PRNG to assign gender randomly every time the user buys a cow.
Unique Name
The idea of this feature is that each cow has a different name, and only one type of name can exist at a time.
So every time the user buys a cow, apart from the cow data, the cow name will also be stored in temporary storage. This data will live as long as the cow is still alive.
For example, if someone already has a cow named "Cloud", we can't buy a cow and give it the same name.
Instead, we can name it "CLouD", as the contract will interpret it as a different name.
Auctions
Auction is one of the most exciting improvements on Cowchain Farm. Now, users can interact with each other.
User with unique cow names, a specific gender, good stats, and more mature cow can auction their cow at a higher price.
The combination of these factors can pique other user's interest in bidding.
In the soroban smart contract parts, the following functions are responsible for the auction features:
fn register_auction(
env: Env,
user: Address,
cow_id: String,
auction_id: String,
price: u32,
) -> AuctionResult;
fn bidding(env: Env, user: Address, auction_id: String, bid_price: u32) -> AuctionResult;
fn finalize_auction(env: Env, auction_id: String) -> AuctionResult;
fn get_all_auction(env: Env) -> AuctionResult;
Following is the sequence of processes that occur when a user starts an auction:
register_function
When this function is called, the user's cow will be registered to be auctioned and put into the auction list.
Once started, the auction will be alive for 12 hours.
bidding
This will be called whenever the user bids at an auction.
This function will transfer user funds to a temporary holding account for the bid amount.
If someone outbid the highest bidder, then the funds of the previous highest bidder will be refunded.
finalize_auction
This function must be called every time an auction is ended.
This will transfer the ownership of the cow to the auction winner and transfer the funds to the user who started the auction.
This function can be called manually by the user or automatically handled by the notification service.
get_all_auction
This function will return the data of all ongoing auctions that happen inside the Cowchain Farm smart contract.
Notification Service
The notification service is the most significant improvement on Cowchain Farm, which benefits users greatly.
Now we have a service that will let us know when:
- Your cow starts to feel hungry.
- You win an auction.
- Your funds are refunded because someone outbid you at an auction.
This service consists of 2 parts, the Dart CLI and the Notification Mobile App.
Dart CLI
Built using Dart and Flutter Stellar SDK, this tool runs on a Cloud Server listening to any event emitted by Cowchain Farm smart contract.
All events received by the Dart CLI will be processed, and the Dart CLI will determine whether the notification should be sent immediately or scheduled to be sent later.
This Dart CLI will also finalize the auctions that are due. This way, users can rest assured knowing that the auction will be processed automatically.
Notification Mobile App
User need to install the Notification Mobile App on their phone to receive notifications about Cowchain Farm.
Inside the app, users then need to register the Account ID or Public Key of the Stellar wallet they used to play Cowchain Farm.
That's all you need to do to receive the notification.
How to install the app?
Well, there are 2 ways you can do it:
Clone the Cowchain Farm App repository, build the Android APK, and install it directly to your phone.
Download the prebuilt Android APK at this DropBox link.
Due to some development limitations, for now, the app is only available on Android.
Tech Stack and Source Code
Following is the tech stack and source code used to build the Cowchain Farm Dapp environment:
1. Cowchain Farm Smart Contract
Built using Rust and Soroban SDK.
You can find the source code and documentation at Cowchain Farm Soroban repository.
2. Cowchain Farm Web App & Mobile Notification
Built using Flutter, Flutter Stellar SDK and OneSignal.
You can find the source code and documentation at Cowchain Farm App repository.
3. Cowchain Farm Notification Service
Built using Dart, Flutter Stellar SDK and OneSignal.
The Dart CLI for notification service was deployed inside a Docker container in a cloud server that runs Ubuntu.
And to create Dart CLI's executable that run on Linux, we use a continuous integration (CI) provider, Codemagic.
You can find the source code and documentation at Cowchain Farm Alert repository.
Live Web App & Youtube
You can watch the Web Demo & brief explanation about Cowchain Farm's latest upgrade on the Youtube link here.
You can also try the live application on Cowchain Farm WebApp.
Ensure that you already have a Stellar TESTNET account and have the Freighter extension installed and enabled in your browser.
Also, ensure the Experimental Mode is enabled in the Freighter extension settings.
Top comments (0)