# Sway tx fields input\_owner

**URL:** <https://forum.fuel.network/t/sway-tx-fields-input-owner/1884>\
**Category:** Sway\
**Created:** [February 23, 2023, 8:22pm UTC](https://forum.fuel.network/t/sway-tx-fields-input-owner/1884 "2023-02-23T20:22:41Z")\
**Posts on this page:** 4\
**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 23, 2023, 8:22pm UTC](https://forum.fuel.network/t/sway-tx-fields-input-owner/1884/1 "2023-02-23T20:22:41Z")

</div>

i am reading the code of OTC predicate. I am confused about the `input_owner()` here. I am not very clear about how fuel tx is constructed.  
what is the index `0` and `1` here for?  
why does checking this `input_owner` can make sure someone send coins along with the tx?  
fuel-book/sway-book does not talk much about the tx and fuel-specs only lists the specs.  
Can someone ELI5? want to dig deeper into this and know better.

```rust
    // Check if the transaction contains a single input coin from the receiver, to cancel their own order (in addition to this predicate)
    if input_count() == 2u8 {
        if input_owner(0).unwrap() == RECEIVER
            || input_owner(1).unwrap() == RECEIVER
        {
            return true;
        };
    };

```

[https://github.dev/FuelLabs/sway-applications/blob/4d497d25df0e88ee29d8b6e6c7055aac83c17842/OTC-swap-predicate/project/predicates/swap-predicate/src/main.sw#L32-L38](https://github.dev/FuelLabs/sway-applications/blob/4d497d25df0e88ee29d8b6e6c7055aac83c17842/OTC-swap-predicate/project/predicates/swap-predicate/src/main.sw#L32-L38)

---

<div class="post-metadata">

**Author:** ![Simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simon](https://forum.fuel.network/u/Simon)\
**Post date:** [February 23, 2023, 10:22pm UTC](https://forum.fuel.network/t/sway-tx-fields-input-owner/1884/2 "2023-02-23T22:22:47Z")

</div>

The idea here is that the address specified as the receiver of the proposed swap can cancel the swap and recover the funds. In order to do this, they can submit a simple transaction which spends the predicate.

This transaction will have exactly two inputs: an input coin (to pay for gas) and the coin belonging to the predicate itself. The input coin contains a signature of the owner over the transaction hash, and this is what allows `input_owner()` to deduce the transaction sender.

So this block of code says:

"If there are exactly two inputs, check if the first one (index 0) is the `RECEIVER`. If it isn’t, check if the second one (index 1) is the `RECEIVER`.

If either of the inputs belongs to the `RECEIVER`, the predicate returns `true` and is spendable"

A transaction to execute the swap must contain at least _three_ inputs: a coin for gas, the requested coin for the swap, and the coin belonging to the predicate. So in this case, we don’t enter the above block of code, and instead the conditions of the swap are evaluated.

---

<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 24, 2023, 1:37am UTC](https://forum.fuel.network/t/sway-tx-fields-input-owner/1884/3 "2023-02-24T01:37:04Z")

</div>

thank you for the detailed explanation! very helpful!

---

<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 16, 2023, 9:38pm UTC](https://forum.fuel.network/t/sway-tx-fields-input-owner/1884/4 "2023-03-16T21:38:03Z")

</div>

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