# \`with\_outputs()\`

**URL:** https://forum.fuel.network/t/with-outputs/1890
**Category:** Rust SDK
**Created:** [February 25, 2023, 2:13am UTC](https://forum.fuel.network/t/with-outputs/1890 "2023-02-25T02:13:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zzzzt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/zzzzt/32/724_2.png) [@zzzzt](https://forum.fuel.network/u/zzzzt)
#### Post date: [February 25, 2023, 2:13am UTC](https://forum.fuel.network/t/with-outputs/1890/1 "2023-02-25T02:13:36Z")

</div>

`with_outputs` can be attached to ScriptCall or ScriptCallHandler  
an [example](https://github.com/FuelLabs/sway-applications/blob/cbf79a7c5daa1f0fb34a750983d18ddf9751cf24/OTC-swap-predicate/project/predicates/swap-predicate/tests/utils/mod.rs#L158-L170)  
What does it do here? Does this mean the expected transaction output for the script? The script call will return some error if the output is not the same as the outputs I attached when executing the script?

```rust
    let script_call = ScriptCallHandler::<()>::new(
        vec![],
        UnresolvedBytes::default(),
        taker_wallet.clone(),
        provider.clone(),
        Default::default(),
    )
    .with_inputs(vec![input_predicate, input_from_taker])
    .with_outputs(vec![
        output_to_receiver,
        output_to_taker,
        output_asked_change,
    ])

```

---

<div class="post-metadata">

### Author: ![ControlCplusControlV](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/controlcpluscontrolv/32/999_2.png) [@ControlCplusControlV](https://forum.fuel.network/u/ControlCplusControlV)
#### Post date: [February 28, 2023, 2:11am UTC](https://forum.fuel.network/t/with-outputs/1890/2 "2023-02-28T02:11:58Z")

</div>

This is because each transaction is spending UTXOs, so to give a better model here are some basic facts about the FuelVM

1. Each Contract is technically represented by a UTXO, when you interact with that a contract that UTXO is spent, and a new one is created
2. You must declare all UTXOs which will be spend when you send a transaction

And so before sending a transaction you must attach all input UTXOs, and all output UTXOs, which will include any coins transferred, any contracts which are called or change their state, and any changed balances. So you can’t arbitrarily attach outputs on a transaction, and that’s why your tx will fail without those exact outputs, and why you need to call `append_variable_outputs` on a transaction which mints new coins, to tell the transaction to expect new Outputs from the transaction (and why you need to declare all contract inputs ahead of time)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)
#### Post date: [March 20, 2023, 10:12pm UTC](https://forum.fuel.network/t/with-outputs/1890/3 "2023-03-20T22:12:57Z")

</div>

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