Micro Cow combines Rust-based smart contracts built with Linera, and a web app client to access the smart contracts functionality built with one of the most popular cross-platform frameworks, Flutter.
Micro Cow smart contract will cover several capabilities of Linera that exist in the Devnet, which include:
- Authentication
- Cross-Chain Messages
- Custom Types
- Contract Instantiation
- Instantiation Argument
- Application Parameters
- Channel Subscription
While the Micro Cow web app will cover the following:
- Setting Linera wallet through calls to node service
- Calling Linera smart contract function using GraphQL
This article is specifically about the Flutter web app for Micro Cow.
Discussion for Micro Cow smart contract is in the Micro Cow Linera repository.
The Micro Cow web app in this repository was developed
using Flutter version 3.22.2
and Dart version 3.4.3
-
Clone the repository:
git clone https://github.com/hasToDev/micro_cow_app.git
-
Install all the project dependencies:
flutter pub get
-
Run on local browser (web-port is optional between 0-65535):
flutter run --web-renderer canvaskit -d web-server --web-port 45454
-
Generate the release build for Micro Cow Web app:
flutter clean flutter pub get flutter build web --web-renderer canvaskit --release
Before playing Micro Cow, make sure the Linera GraphQL Service is alive by running command linera service
on
your
terminal.
- on Login page, click the Wallet Setting to setup your Linera Wallet first.
- on Setting page, enter the GraphQL service address (it is advisable to use http://127.0.0.1:8080 instead of http://localhost:8080), then click check button.
- If your GraphQL service address is valid, you will see the list of ChainID that you can use to play Micro Cow, choose one of them.
- Don't forget to enter Application ID (that you received after deploy the smart contract) and Root Chain ID (the ChainID that you use to deploy the smart contract).
- click confirm on Setting page, after finish fill out all the required fields.
- Now you can start Login to play the game.
- Web app will automatically request Micro Cow application, if it doesn't exist in your chain.
- Web app will also initialize your account with 10000 LINERA token if this is the first time you play the game.
- This whole initial process could take up to 40 seconds, give or take.
- You can Buy your cow at the market using LINERA token in your balance.
- When buying the cow, choose your Cow name wisely because the name is unique in Micro Cow. The cow gender will be assigned randomly by the smart contract.
- Feed cow every 6 hours intervals. If you don't feed the cow within 24 hours, the cow will die.
- After your cow reaches 3 days of age, you can start selling it back to the market.
- Of course, you can choose to keep feeding the cow. As the cow grows, the price increases (or decreases).
- The feeding interval plays an essential role in increasing or decreasing your cow's value. As a rule, always feed your cow no more than 18 hours after its last meal.
The cow's hunger level will increase every 6 hours. Here are the levels of cow hunger in Micro Cow every 6 hours since its last feed:
- Full, hour 0 - 6
At this level, you don't need to feed the cow. - Hungry, hour 6 - 12
The cow feels a little hungry, and this is the optimal time to feed the cow.
Feeding at this level will increase cow's price by 0.5%. - Peckish, hour 12 - 18
Cow hunger grows; feed the cow right now to keep it healthy.
Feeding at this level will increase cow's price by 0.25%. - Famished, hour 18 - 24
Cow hungers at its peak feed the cow immediately.
Feeding at this level will decrease cow's price by 1%, but the cow will live to see another day.
The cows that we have will be able to be sold after they are 3 days old.
If you try to sell a cow that is still underage, Micro Cow contract will not execute the sale and will only provide certain information.
Before executing the sale, Micro Cow contract will evaluate the cow price and ask you to confirm the selling price.
The Micro Cow is distributed under an MIT license. See the LICENSE for more information.