# Cannot generate a contract instance when there are enums with the same name in the project

**URL:** <https://forum.fuel.network/t/cannot-generate-a-contract-instance-when-there-are-enums-with-the-same-name-in-the-project/2783>\
**Category:** Rust SDK\
**Created:** [June 21, 2023, 9:01pm UTC](https://forum.fuel.network/t/cannot-generate-a-contract-instance-when-there-are-enums-with-the-same-name-in-the-project/2783 "2023-06-21T21:01:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [June 21, 2023, 9:01pm UTC](https://forum.fuel.network/t/cannot-generate-a-contract-instance-when-there-are-enums-with-the-same-name-in-the-project/2783/1 "2023-06-21T21:01:39Z")

</div>

I wrote a smart contract in sway with the following dependencies:

```auto
[dependencies]
nft = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1" }
ownership = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1" }

```

Both of the libraries have an enum with the same name - `AccessError`:

> <https://github.com/FuelLabs/sway-libs/blob/ff949a7b2c2bd60a0269298ee996f60120b4341a/libs/ownership/src/errors.sw>

> <https://github.com/FuelLabs/sway-libs/blob/ff949a7b2c2bd60a0269298ee996f60120b4341a/libs/nft/src/nft_core/errors.sw>

After building the contract I get an ABI json file with both of these enums listed:

```json
"types": [
    ...
    {
      "typeId": 3,
      "type": "enum AccessError",
      "components": [
        {
          "name": "OwnerDoesNotExist",
          "type": 0,
          "typeArguments": null
        },
        {
          "name": "SenderNotOwner",
          "type": 0,
          "typeArguments": null
        },
        {
          "name": "SenderNotOwnerOrApproved",
          "type": 0,
          "typeArguments": null
        }
      ],
      "typeParameters": null
    },
    {
      "typeId": 4,
      "type": "enum AccessError",
      "components": [
        {
          "name": "CannotReinitialized",
          "type": 0,
          "typeArguments": null
        },
        {
          "name": "NotOwner",
          "type": 0,
          "typeArguments": null
        }
      ],
      "typeParameters": null
    },
   ...

```

And when I try to use this ABI in my Rust code

```rust
abigen!(Contract(
    name = "ContractInstance",
    abi = "../contract/out/debug/contract-abi.json"
));

```

, I get the following error:

```sh
$ cargo run

   Compiling script v0.1.0 (./script)
error[E0428]: the name `AccessError` is defined multiple times
 --> src/model.rs:3:1
  |
3 | / abigen!(Contract(
4 | | name = "ContractInstance",
5 | | abi = "../contract/out/debug/contract-abi.json"
6 | | ));
  | |__^ `AccessError` redefined here
  |
  = note: `AccessError` must be defined only once in the type namespace of this module
  = note: this error originates in the macro `abigen` (in Nightly builds, run with -Z macro-backtrace for more info)

```

The problem is gone after renaming one of the `AccesError` occurrences manually in the ABI json file, but I think that this behavior should be fixed.

> **fuelup show**
>
> ```sh
> active toolchain
> -----------------
> beta-3-aarch64-apple-darwin (default)
> forc : 0.37.3
> - forc-client
> - forc-deploy : 0.37.3
> - forc-run : 0.37.3
> - forc-doc : 0.37.3
> - forc-explore : 0.28.1
> - forc-fmt : 0.37.3
> - forc-index : 0.11.2
> - forc-lsp : 0.37.3
> - forc-tx : 0.37.3
> - forc-wallet : 0.2.2
> fuel-core : 0.17.11
> fuel-indexer : 0.11.2
> 
> ```

---

<div class="post-metadata">

**Author:** ![iqdecay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/iqdecay/32/1277_2.png) [@iqdecay](https://forum.fuel.network/u/iqdecay)\
**Post date:** [June 26, 2023, 1:00pm UTC](https://forum.fuel.network/t/cannot-generate-a-contract-instance-when-there-are-enums-with-the-same-name-in-the-project/2783/2 "2023-06-26T13:00:08Z")

</div>

Hey,  
First of all thanks for including your toolchain info in your post that’s very helpful.  
It looks like your issue can be solved by calling `forc build --json-abi-with-callpaths` inside your Sway project. If it still doesn’t work let us know in this thread.  
This is documented [here](https://rust.fuel.network/v0.43.0/abigen/the-abigen-macro.html?highlight=callpath#type-paths), and will be deprecated as soon as the `forc` tool uses this option by default, which should in the near future.

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [June 26, 2023, 2:56pm UTC](https://forum.fuel.network/t/cannot-generate-a-contract-instance-when-there-are-enums-with-the-same-name-in-the-project/2783/3 "2023-06-26T14:56:37Z")

</div>

Hey, thanks! That solved the problem in rust for me. However, I cannot use the same generated code with typescript now, because ts typegen generates export statements like this one:

```ts
export type nft::nft_core::errors::AccessErrorInput = Enum<{ OwnerDoesNotExist: [], SenderNotOwner: [], SenderNotOwnerOrApproved: [] }>;

```

and these statements are illegal in typescript (because of `::` I think).

That’s not a blocker for me, I’ll generate the ABI without `--json-abi-with-callpaths` flag for typescript, but I think there should be a unified way for both SDKs
