In this tutorial, you learn how to implement a smart contract that stores and manipulates an integer value on the Stacks 2.0 blockchain. By the end of this tutorial, you will ...
* Have experienced test-driven development with Clarity
* Understand more Clarity language design principles
The Stacks 2.0 blockchain is currently in development and could experience resets and downtimes. To make sure you're not running into any challenges related to the status of the network, please open up the [Status Checker](http://status.test-blockstack.com/) and confirm that all systems are operational. If some systems seem to have issues, it is best to wait until they are back up before you proceed with the next steps.
Finally, the project dependencies are installed and your project is ready for development. Because you already completed the [Hello World tutorial](tutorial.html), the project structure is familiar to you. The main difference is that we have additional tests for a new counter smart contract.
Smart contracts are often developed in a test-driven approach. This not only improves code quality, but also removes the need to push every iteration to the blockchain before executing it. We will do the same in this project. Now, let's run the tests and review the results:
It looks like we see some failed tests! That is on purpose - we will implement the new smart contract in the next steps! After every step in this tutorial, we will rerun the tests to ensure we're on the right track.
## Step 3: Developing a smart contract
Let's get familiar with the tests to understand what the new smart contract should look like
You will see a [Mocha](https://mochajs.org/) test suite. This file describes the tests for the counter smart contract. Notice how the smart contract is instantiated on line 8 of file `counter.ts`:
counterClient = new Client("SP3GWX3NE58KXHESRYE4DYQ1S31PQJTCRXB3PE9SB.counter", "counter", provider);
```
That tells us that the new smart contract is named `counter` and that it should be found in the following file: `contracts/counter.clar`. Note that the `contracts` folder is assumed as the base folder and that every Clarity file has the suffix `.clar`.
The file was already created during the project setup.
2. Using your editor, open `contracts/counter.clar`. You will notice the file already includes some content:
```cl
;; define counter variable
;; increment method
;; decrement method
;; counter getter
```
What you see are four one-line comments. In Clarity, a comment line is started with `;;`. As you can see, the comments indicate the structure of the smart contract we are going to implement.
Let's declare a counter variable and define a public getter method:
The [`define-data-var`](https://docs.blockstack.org/core/smart/clarityref#define-data-var) statement initializes a new integer variable named `counter` and sets the value to `0`. It is important to note that all definition statements in Clarity need to be at the top of the file.
To provide access to the `counter` variable from outside of the current smart contract, we need to declare a public function to get it. The last lines of the code add a public `get-counter` function. The [`var-get`](https://docs.blockstack.org/core/smart/clarityref#var-get) statement looks for a variable in the contract's data space and returns it.
First, the [`begin`](https://docs.blockstack.org/core/smart/clarityref#begin) statement evaluates the multi-line expressions and returns the value of the last expression. In this case, it is used to set a new value and return the new value.
Next, a [`var-set`](https://docs.blockstack.org/core/smart/clarityref#var-set) is used to set a new value for the `counter` variable. The new value is constructed using the [`+`](https://docs.blockstack.org/core/smart/clarityref#-add) (add) statement. This statement takes a number of integers and returns the result. Along with add, Clarity provides statements to subtract, multiply, and divide integers. Find more details in the [Clarity language reference](https://docs.blockstack.org/core/smart/clarityref).
5. Next, implement a new public function `decrement` to subtract `1` from the `counter` variable. You should have all knowledge needed to succeed at this!
Your new smart contract is ready to be deployed to the Stacks 2.0 blockchain. You should be familiar with the steps from the ["Hallo, World" tutorial](https://docs.blockstack.org/core/smart/tutorial.html#deploy-the-contract).
As soon as you successfully deploy your contract, you can play around with the contract and verify the functionality by calling all public methods you implemented. Here's a suggested order:
{% include note.html content="As you can see, read-only function calls don't require a transaction to complete. This is because the method doesn't require a state change." %}