Skip to content

Simple counter in Rust. Increment, decrement, and reset.

Notifications You must be signed in to change notification settings

frol/rust-counter

Repository files navigation

Counter example in Rust

Open in Gitpod!

Description

This contract implements simple counter backed by storage on blockchain. Contract in contract/src/lib.rs provides methods to increment / decrement counter and get it's current value or reset.

Plus and minus buttons increase and decrease value correspondingly. When button L is toggled, counter will add or minus 10 a time. RS button is for reset. LE and RE buttons to let the robot wink at you.

To Run

Open in the Gitpod link above or clone the repository.

git clone https://github.com/near-examples/rust-counter

Install dependencies:

yarn

Make sure you have near-shell by running:

near --version

If you need to install near-shell:

npm install near-shell -g

Login

If you do not have a NEAR account, please create one with NEAR Wallet.

In the project root, login with near-shell by following the instructions after this command:

near login

Modify the top of src/config.js, changing the CONTRACT_NAME to be the NEAR account that was just used to log in.


const CONTRACT_NAME = 'YOUR_ACCOUNT_NAME_HERE'; /* TODO: fill this in! */

Start the example!

yarn start

To Test

cd contract
cargo test -- --nocapture

To Explore

  • contract/src/lib.rs for the contract code
  • src/index.html for the front-end HTML
  • src/main.js for the JavaScript front-end code and how to integrate contracts
  • src/test.js for the JS tests for the contract

About

Simple counter in Rust. Increment, decrement, and reset.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published