# Compilation error following the sample counter contract using forc build?

**URL:** <https://forum.fuel.network/t/compilation-error-following-the-sample-counter-contract-using-forc-build/4114>\
**Category:** Sway\
**Created:** [February 2, 2024, 10:40am UTC](https://forum.fuel.network/t/compilation-error-following-the-sample-counter-contract-using-forc-build/4114 "2024-02-02T10:40:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sheys](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sheys/32/2075_2.png) [@Sheys](https://forum.fuel.network/u/Sheys)\
**Post date:** [February 2, 2024, 10:40am UTC](https://forum.fuel.network/t/compilation-error-following-the-sample-counter-contract-using-forc-build/4114/1 "2024-02-02T10:40:12Z")

</div>

Lines of codes:

```auto
 contract;

storage {
    //declare a storage variable
    counter: u64 = 0,
}

abi Counter {
    //reads and write to storage
    #[storage(read, write)]
    fn increment();

    //reads from storage
    #[storage(read)]
    fn counter() -> u64;
}

impl Counter for Contract {
    #[storage(read)]
    fn counter() -> u64 {
        //using implicit return
        return storage.counter;
        
    }

    #[storage(read, write)]
    fn increment() {
        storage.counter = storage.counter + 1;
    }
}

```

My toolchain using “$fuelup show”:

Default host: x86\_64-unknown-linux-gnu  
fuelup home: /home/sheys/.fuelup

## installed toolchains

beta-3-x86\_64-unknown-linux-gnu  
beta-4-x86\_64-unknown-linux-gnu (default)  
latest-x86\_64-unknown-linux-gnu

## active toolchain

beta-4-x86\_64-unknown-linux-gnu (default)  
forc : 0.46.1  
- forc-client  
- forc-deploy : 0.46.1  
- forc-run : 0.46.1  
- forc-crypto : not found  
- forc-doc : 0.46.1  
- forc-explore : 0.28.1  
- forc-fmt : 0.46.1  
- forc-lsp : 0.46.1  
- forc-tx : 0.46.1  
- forc-wallet : 0.3.0  
fuel-core : 0.20.5  
fuel-core-keygen : Error getting version string

## fuels versions

forc : 0.45  
forc-wallet : 0.45

Now, I could use beta-3 but I also have trouble deploying to beta-3

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [February 2, 2024, 8:18pm UTC](https://forum.fuel.network/t/compilation-error-following-the-sample-counter-contract-using-forc-build/4114/2 "2024-02-02T20:18:07Z")

</div>

Hello @Sheys,

I hope you’re doing well. I wanted to address a couple of points:

1. I’ve attempted to reproduce the issue you mentioned but haven’t been successful so far. To gain a better understanding, could you confirm if the error occurs when you run `forc build` in the root directory of your Sway project? Additionally, it would be really helpful if you could share the specific error message you’re encountering. This will enable me to diagnose the problem more accurately.

2. Regarding the beta-3 network, it has been officially deprecated. For more details, you can refer to this link: [Sunsetting Beta-3 Testnet](https://forum.fuel.network/t/sunsetting-beta-3-testnet/3145). To deploy on the beta-4 network, you can use the following command: `forc deploy --testnet`.

Let me know if you need more help! 🙂

---

<div class="post-metadata">

**Author:** ![Sheys](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sheys/32/2075_2.png) [@Sheys](https://forum.fuel.network/u/Sheys)\
**Post date:** [February 8, 2024, 3:08pm UTC](https://forum.fuel.network/t/compilation-error-following-the-sample-counter-contract-using-forc-build/4114/3 "2024-02-08T15:08:36Z")

</div>

Hello @calldelegation, thank you.

1. Here’s the compilation error it shows using `forc build` in the root directory of my Sway project:

```auto
sheys@DESKTOP-MRD72SV:~/fuelvm-projects/counter$ forc build
 Compiling library core (/home/sheys/.forc/git/checkouts/std-9be0d6062747ea7/512a3386f8961185188302f391ccc96553d23a7a/sway-lib-core)
 Compiling library std (git+https://github.com/fuellabs/sway?tag=v0.46.1#512a3386f8961185188302f391ccc96553d23a7a)
 Compiling contract counter (/home/sheys/fuelvm-projects/counter)
warning
 --> /home/sheys/fuelvm-projects/counter/src/main.sw:5:5
  |
3 |
4 | //declare a storage variable
5 | counter: u64 = 0,
  | ------- This storage declaration is never accessed and can be removed.
6 | }
  |
____

error
  --> /home/sheys/fuelvm-projects/counter/src/main.sw:22:16
   |
20 |
21 | //using implicit return
22 | return storage.counter;
   | ^^^^^^^^^^^^^^^ Mismatched types.
expected: u64
found: StorageKey<u64>.
help: Return statement must return the declared function return type.
23 |
24 | }
   |
____

error
  --> /home/sheys/fuelvm-projects/counter/src/main.sw:28:9
   |
26 |
27 | fn increment() {
28 | storage.counter = storage.counter + 1;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This expression is not valid on the left hand side of a reassignment.
29 | }
30 | }
   |
____

error
  --> /home/sheys/fuelvm-projects/counter/src/main.sw:20:5
   |
18 |
19 | #[storage(read)]
20 | fn counter() -> u64 {
   | _____ ^
21 | | //using implicit return
22 | | return storage.counter;
23 | |
24 | | }
   | | _____ ^ This path must return a value of type "u64" from function "counter", but it does not.
25 |
26 | #[storage(read, write)]
   |
____

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

```

I recently read that there’s a storage issue with beta-4 testnet [here](https://forum.fuel.network/t/error-compiling-counter-smart-contract/2482/2), I don’t think that has been resolved yet… But how can I move forward?

1. Regarding point 2, thanks for the information 👍
