# Replicate transaction calculation in rust

**URL:** <https://forum.dfinity.org/t/replicate-transaction-calculation-in-rust/37659>\
**Category:** Rust\
**Created:** [November 22, 2024, 8:22am UTC](https://forum.dfinity.org/t/replicate-transaction-calculation-in-rust/37659 "2024-11-22T08:22:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harrycheck](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@harrycheck](https://forum.dfinity.org/u/harrycheck)\
**Post date:** [November 22, 2024, 8:22am UTC](https://forum.dfinity.org/t/replicate-transaction-calculation-in-rust/37659/1 "2024-11-22T08:22:22Z")

</div>

Hey dfinity devs , I am trying to replicate the hash calculation in rust , here is my code ( written in c-style)

```auto

// c wrapper for hash
#[no_mangle]
pub extern "C" fn c_transaction_hash(
    from: *const i8,
    to: *const i8,
    amount: u64,
    fee: u64,
    memo: u64,
    created_at_time: u64,
    use_created_at_time: bool,
    icrc1_memo_hex_str: *const i8,
    use_memo : bool,
) -> *mut i8 {
    let from = unsafe { std::ffi::CStr::from_ptr(from).to_str().unwrap() };
    let to = unsafe { std::ffi::CStr::from_ptr(to).to_str().unwrap() };
    let icrc1_memo = if icrc1_memo_hex_str.is_null() {
        None
    } else {
        Some(
            unsafe { std::ffi::CStr::from_ptr(icrc1_memo_hex_str) }
            .to_str()
            .map(|s| ByteBuf::from(hex::decode(s).unwrap()))
            .unwrap()
        )
    };
    let transaction = Transaction {
        operation: Operation::Transfer {
            from: AccountIdentifier::from_str(from).unwrap(),
            to: AccountIdentifier::from_str(to).unwrap(),
            amount: Tokens::from_e8s(amount),
            fee: Tokens::from_e8s(fee),
            spender: None,
        },
        memo: Memo(memo),
        created_at_time: match use_created_at_time {
            true => Some(TimeStamp::from_nanos_since_unix_epoch(created_at_time)),
            false => None,
        },
        icrc1_memo : match use_memo {
            true => icrc1_memo,
            false => None,
        },
    };

    let hash = transaction.hash().to_string();
    let c_str = CString::new(hash).unwrap();
    c_str.into_raw()
}

```

I noticed that some time we need to specify created\_at\_time:  
8f3a2b5e0b32f0cfca2f2c5aef4cc29fe064006837eaf987707299677ceab13e

sometime we need to put created\_at\_time as None , like this one  
7fe4f93f2a4af594a1d0d25f69f9e773b933a8f1935501291aaaf17414c7e375

I can’t post the directly dashboard transaction link as it is prohibited

I noticed this weird behaviour with non-empty icrc1\_memo.

Can anyone confirm this ?  
Even better , a link to the source that implement the **dashboard transaction hash** will be greatly appreciated.
