How to convert a byte array into something I can read?

How can I convert my byte array obtained from the ‘tx_script_bytecode()’ function into something readable and access parts of my transaction, like inputs and outputs? Is there also a way to manipulate this byte array?

It can be very useful if there is some formatting, even if it’s through fuels-ts, for the function’s return, so I can validate if I managed to manipulate the bytes as I wanted.

Thats my sway code:
Screenshot at Jan 23 11-33-47

Hi there!

Thanks for sharing your issue :palm_tree:

My first question is: what are you trying to do? I need to know if you want a decoded output in TS SDK or just the terminal.

Another question is: do you need to read the bytecode or are you trying to access information regarding the transaction?

It looks like your best choice might be tx_script_data. (See source)

foo() {
let script_data: u64 = tx_script_data();

However, you don’t need these functions in order to access inputs and outputs.

We have functions in place for inputs (see source)

There are useful functions for outputs (see source)

Please share more context about your issue so I can provide further support.

Right, I’ve been checking these functions but still haven’t been able to solve my problem. I am using a predicate to validate a signature over the hash of a transaction, but I need the transaction hash without the coins (Inputs). My idea was to rewrite the transaction through the predicate without these inputs to obtain the hash.

Hi there
IN that case, you can use std::tx::tx_id

Check the source code for further details.

/// Get the Transaction ID of the current transaction.
/// # Returns
/// * [b256] - The Transaction ID of the current transaction.
/// # Examples
/// ```sway
/// use std::tx::tx_id;
/// fn foo() {
///     let tx_id: b256 = tx_id();
///     log(tx_id);
/// }
/// ```
pub fn tx_id() -> b256 {
    asm(ptr: TX_ID_OFFSET) {
        ptr: raw_ptr

ok, thanks for your answer.
But i like a ref or exemple of generation to tx_id()…this returned value is a hash of transaction with const (input) included on hash