# Successful transaction marked as failed

**URL:** <https://forum.fuel.network/t/successful-transaction-marked-as-failed/6614>\
**Category:** General\
**Created:** [September 15, 2024, 11:07pm UTC](https://forum.fuel.network/t/successful-transaction-marked-as-failed/6614 "2024-09-15T23:07:02Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [September 23, 2024, 3:01pm UTC](https://forum.fuel.network/t/successful-transaction-marked-as-failed/6614/8 "2024-09-23T15:01:32Z")

</div>

@mpoplavkov I am deeply sorry if my explanations weren’t clear enough

## About your code:

To avoid the transaction reverting, we need to specifically set the transaction’s `gasLimit` and the `maxFee`:

```ts
  let request = new ScriptTransactionRequest();

    // Adds a `CoinOutput` in favor of the receiver to the TX outputs 
    request = wallet.addTransfer(request, {destination: destinationB256Address, amount: fractionalAmount, assetId});

    const txCost = await wallet.getTransactionCost(request);
    request.gasLimit = txCost.gasUsed;
    request.maxFee = txCost.maxFee;

    // Fetches and add resources (ChageOutput is added for the resources owner)
    request = await wallet.fund(request, txCost);

```

## Why did the funds get transferred?

- **Gas Limit Not Set** : The transaction’s `gasLimit` was not set, so it defaulted to `0`. The network accepts the transaction but it reverts due to an `OutOfGas` error during execution.
- **Spent Inputs** : After the transaction reverts, the Fuel VM still spends the transaction inputs for the reason of preventing users from spamming the network with invalid transactions without incurring any fees.
- **Fee Deduction** : The VM deducts the fee for its use up to the point of failure from the total amount of the spent inputs.
- **UTXO Generation for `CoinOutput`** : The VM generates new UTXOs for every `CoinOutput` specified in the transaction. This is why the recipient received their funds despite the transaction reverting. So, since resources were spent, the VM will also generate new ones specified by every `CoinOutput`.
- **Change UTXO Creation** : After generating UTXOs for each `CoinOutput`, the VM creates a new UTXO with the remaining amount (change) for the address specified in the `ChangeOutput` of that asset ID. This step ensures that the entity funding the transaction doesn’t lose all their resources. This is why the amount of the `ChangeOutput` is determined only during execution time.

Please let me know if this clarifies your question.

---

_[View the full topic](https://forum.fuel.network/t/successful-transaction-marked-as-failed/6614)._
