# Error compiling Counter Smart Contract

**URL:** <https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482>\
**Category:** General\
**Created:** [April 30, 2023, 9:04am UTC](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482 "2023-04-30T09:04:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vonsete](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/vonsete/32/1362_2.png) [@vonsete](https://forum.fuel.network/u/vonsete)\
**Post date:** [April 30, 2023, 9:04am UTC](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482/1 "2023-04-30T09:04:00Z")

</div>

I am following the instructions [Building A Smart Contract - The Fuel Book](https://fuelbook.fuel.network/master/quickstart/smart-contract.html)

When I try to build the smart contract the following errors are shown:

~/fuel-project/counter-contract$ forc build  
WARNING! unused manifest key: constants  
WARNING! unused manifest key: constants  
Compiling library core (/home/alfonso/.forc/git/checkouts/std-9be0d6062747ea7/2d16d70ab9d5ab0de0255941048f811b6d07c6b1/sway-lib-core)  
Compiling library std (git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1)  
Compiling contract counter-contract (/home/alfonso/fuel-project/counter-contract)  
warning  
 → /home/alfonso/fuel-project/counter-contract/src/main.sw:4:5  
|  
2 |  
3 | storage {  
4 | counter: u64 = 0,  
| ------- This storage declaration is never accessed and can be removed.  
5 | }  
|

* * *

error  
 → /home/alfonso/fuel-project/counter-contract/src/main.sw:18:9  
|  
16 |  
17 | fn count() → u64 {  
18 | storage.counter  
| ^^^^^^^^^^^^^^^ Mismatched types.  
expected: u64  
found: StorageKey.  
help: Implicit return must match up with block’s type.  
19 | }  
|

* * *

error  
 → /home/alfonso/fuel-project/counter-contract/src/main.sw:18:9  
|  
16 |  
17 | fn count() → u64 {  
18 | storage.counter  
| ^^^^^^^^^^^^^^^ Mismatched types.  
expected: u64  
found: StorageKey.  
help: Function body’s return type does not match up with its return type annotation.  
19 | }  
|

* * *

error  
 → /home/alfonso/fuel-project/counter-contract/src/main.sw:23:9  
|  
21 |  
22 | fn increment() {  
23 | storage.counter = storage.counter + 1;  
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This expression is not valid on the left hand side of a reassignment.  
24 | }  
25 | }  
|

* * *

Aborting due to 3 errors.  
Error: Failed to compile counter-contract

CAn anyone help me?

---

<div class="post-metadata">

**Author:** ![sarah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sarah/32/13_2.png) [@sarah](https://forum.fuel.network/u/sarah)\
**Post date:** [May 1, 2023, 2:29pm UTC](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482/2 "2023-05-01T14:29:25Z")

</div>

It looks like you are using the latest toolchain which has some breaking changes related to storage. Can you update your toolchain to the latest beta-3 versions with the commands below and try again?

`fuelup update`  
`fuelup toolchain install beta-3`  
`fuelup default beta-3`

---

<div class="post-metadata">

**Author:** ![vonsete](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/vonsete/32/1362_2.png) [@vonsete](https://forum.fuel.network/u/vonsete)\
**Post date:** [May 2, 2023, 5:18am UTC](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482/3 "2023-05-02T05:18:42Z")

</div>

Thanks Sarah.  
It solved my issue.

🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [May 23, 2023, 1:18am UTC](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482/4 "2023-05-23T01:18:43Z")

</div>

Closed on May 23, 2023, 1:18am UTC

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
