Can I used tx_id() inside of a predicate?

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.

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

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);

Can you post the implementation of check_signature?

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 {
            return 1;
    return 0;

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

Closing Topic

Problem was on SDK, when estimating gas cost step

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