Error compiling Counter Smart Contract

I am following the instructions Building A Smart Contract - The Fuel Book

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?

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

1 Like

Thanks Sarah.
It solved my issue.

:slight_smile:

1 Like

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