# Error: not enough coins to fit the target

**URL:** <https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690>\
**Category:** Sway\
**Tags:** testnet\
**Created:** [March 7, 2024, 6:36am UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690 "2024-03-07T06:36:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [March 7, 2024, 6:36am UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690/1 "2024-03-07T06:36:44Z")

</div>

Essentially, I have a `Fungible` contract that acts as a “native asset wrapper” that handles minting and burning of assets. The `mint` method is as follows:

```rust
#[storage(read, write)]
fn mint(recipient: Identity, amount: u64) {
    let asset_id = AssetId::new(contract_id(), ZERO_B256);

    let supply = storage.total_supply.get(asset_id);

    storage
        .total_supply
        .insert(asset_id, supply.try_read().unwrap_or(0) + amount);

    mint_to(recipient, ZERO_B256, amount);
}

```

and then a generic contract with the following method:

```rust
#[payable]
#[storage(read, write)]
fn do_something() {
     // do some random stuff here
}

```

within the Typescript SDK, I’m doing the following:

```typescript
[deployer, user1] = await getWallets() // creates two wallets funded with ETH in the local node

...
// deployer deploys both contracts: FungibleContract and TestContract

// balance before: 0
await FungibleContract.functions.mint(toIdentity(user1.address), 10_000).call()
// balance after: 10_000

// issue is here:
TestContract.account = user1 // prank as user1
await TestContract.functions.do_something()
    .callParams({ forward: [10, getAssetId(FungibleContract) })
    .txParams({ variableOutputs: 1 }) // this doesn't solve the error unfortunately
    .call()

```

I’ve verified the `getAssetId(contract)` works well (I’m able to query the balance well). I’ve also verified I have sufficient ETH and FungibleContract assets in both `deployer` and `user1` within the local node.

When I remove the `TestContract.account = user1 ` line (so effectively, the `deployer` is calling the contract instead of `user1`), I don’t get the error `Error: not enough coins to fit the target`.

I know this error has something to do with UTXOs, but can’t wrap my head around this particular issue. Any suggestions?

This is the full error:

```bash
Error: not enough coins to fit the target: 
{
  "response": {
    "data": null,
    "errors": [
      {
        "message": "not enough coins to fit the target",
        "locations": [
          {
            "line": 2,
            "column": 3
          }
        ],
        "path": [
          "coinsToSpend"
        ]
      }
    ],
    "status": 200,
    "headers": {}
  },
  "request": {
    "query": "query getCoinsToSpend($owner: Address!, $queryPerAsset: [SpendQueryElementInput!]!, $excludedIds: ExcludeInput) {\n coinsToSpend(\n owner: $owner\n queryPerAsset: $queryPerAsset\n excludedIds: $excludedIds\n ) {\n ...coinFragment\n ...messageCoinFragment\n }\n}\n\nfragment coinFragment on Coin {\n __typename\n utxoId\n owner\n amount\n assetId\n maturity\n blockCreated\n txCreatedIdx\n}\n\nfragment messageCoinFragment on MessageCoin {\n__ typename\n sender\n recipient\n nonce\n amount\n assetId\n daHeight\n}",
    "variables": {
      "owner": "0xe373620c9fdae7e928ee42001314bf8ab9638cd82a61f4e19a4e27133a419f7b",
      "queryPerAsset": [
        {
          "assetId": "0x3581afea00c726328e2f455738f46f002c89db9b5a1713779988cdff8b5f4150",
          "amount": "1"
        },
        {
          "assetId": "0x0000000000000000000000000000000000000000000000000000000000000000",
          "amount": "1"
        }
      ],
      "excludedIds": {
        "messages": [],
        "utxos": []
      }
    }
  }
}

```

Additionally, this error [could be more user-friendly](https://github.com/FuelLabs/fuels-rs/issues/1237).

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [March 10, 2024, 5:41pm UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690/4 "2024-03-10T17:41:32Z")

</div>

@nedsalk @calldelegation @IGI-111 @Dhaiwat10

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [March 12, 2024, 5:13am UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690/5 "2024-03-12T05:13:08Z")

</div>

@anderson @Torres-ssf ?

---

<div class="post-metadata">

**Author:** ![anderson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/anderson/32/320_2.png) [@anderson](https://forum.fuel.network/u/anderson)\
**Post date:** [March 12, 2024, 9:42am UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690/6 "2024-03-12T09:42:37Z")

</div>

This part seems hacky:

```ts
TestContract.account = user1

```

Are you [generating types](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/generating-types-from-abi.html) for your contract using `typegen`?

Please try [creating a new instance](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/using-generated-types.html) for `user1`, and see if the problem is resolved.

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [March 13, 2024, 4:56am UTC](https://forum.fuel.network/t/error-not-enough-coins-to-fit-the-target/4690/7 "2024-03-13T04:56:32Z")

</div>

thanks for this.

the issue was in my implementation. While I did mention this line above: `TestContract.account = user1 `, I didn’t actually use it in my implementation (i had multiple contracts within the same test context, and missed using this for the main contract).

Effectively, while `user1` had the coins, `deployer` did not. Not using the `TestContract.account = user1 ` line above was still using the `deployer` context (which did not have sufficient coins).

Apologies, and thanks for pointing me in the right direction @anderson!
