# Can I used tx\_id() inside of a predicate?

**URL:** <https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754>\
**Category:** Sway\
**Created:** [June 14, 2023, 2:55pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754 "2023-06-14T14:55:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![guimroque](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/guimroque/32/1462_2.png) [@guimroque](https://forum.fuel.network/u/guimroque)\
**Post date:** [June 14, 2023, 2:55pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/1 "2023-06-14T14:55:42Z")

</div>

I’m currently in the process of constructing a predicate that utilizes the `tx_id()` (transaction identifier), and during the developmental stage, I have implemented it successfully within a script. However, when I integrate the predicate into the system, it appears that the `tx_id()` is yielding a different value that remains unidentified.

By substituting the `tx_id()` within the predicate with a hardcoded value encoded in b256, I am able to successfully validate all the conditions.

---

<div class="post-metadata">

**Author:** ![IGI-111](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/igi-111/32/1348_2.png) [@IGI-111](https://forum.fuel.network/u/IGI-111)\
**Post date:** [June 14, 2023, 3:13pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/2 "2023-06-14T15:13:57Z")

</div>

What’s the transaction like? What values are you getting? How did you calculate the hardcoded value?

---

<div class="post-metadata">

**Author:** ![guimroque](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/guimroque/32/1462_2.png) [@guimroque](https://forum.fuel.network/u/guimroque)\
**Post date:** [June 14, 2023, 6:14pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/4 "2023-06-14T18:14:37Z")

</div>

```auto
fn main() -> bool {
    // Works with I turn the predicate into a script but not works on predicate
    // let tx_id_hash = tx_id();
    // Hardcode value that works on predicate
    let tx_id_hash = 0x0000000000000000000000000000000000000000000000000000000000000001;
    let tx_hash = b256_to_ascii_bytes(tx_id_hash).sha256();
    
    return check_signature(0, tx_hash);
}

```

---

<div class="post-metadata">

**Author:** ![IGI-111](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/igi-111/32/1348_2.png) [@IGI-111](https://forum.fuel.network/u/IGI-111)\
**Post date:** [June 14, 2023, 9:46pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/5 "2023-06-14T21:46:51Z")

</div>

Can you post the implementation of check\_signature?

---

<div class="post-metadata">

**Author:** ![guimroque](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/guimroque/32/1462_2.png) [@guimroque](https://forum.fuel.network/u/guimroque)\
**Post date:** [June 14, 2023, 11:02pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/6 "2023-06-14T23:02:22Z")

</div>

```auto
fn check_signature(index: u64, tx_hash: b256) -> u64 {
    // If the index is bigger than the witness count
    // return false because the signature does not exist
    // and if we try to access it, it will panic
    if (index >= tx_witnesses_count()) {
        return 0;
    }

    // Get the singature from the witness field
    let signature = tx_witness_data::<B512>(index);

    // Check if the signature is valid and if the address
    // is one of the signers list
    if let Result::Ok(pub_key_sig) = ec_recover_address(signature, tx_hash) {
        let address = pub_key_sig.value;
        if (address == signer_configurable {
            log(address);
            return 1;
        }
    }
    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [June 16, 2023, 8:30am UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/7 "2023-06-16T08:30:29Z")

</div>

Can you tell me what the usecase is? Like example of usage

---

<div class="post-metadata">

**Author:** ![guimroque](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/guimroque/32/1462_2.png) [@guimroque](https://forum.fuel.network/u/guimroque)\
**Post date:** [June 20, 2023, 12:28am UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/8 "2023-06-20T00:28:32Z")

</div>

Closing Topic

Problem was on SDK, when estimating gas cost step

---

<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:** [July 10, 2023, 8:29pm UTC](https://forum.fuel.network/t/can-i-used-tx-id-inside-of-a-predicate/2754/9 "2023-07-10T20:29:07Z")

</div>

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