Convert u8 type to bytes

How convert u8 on bytes ?

my confgs:
image

i tryied with:

let u64_value = u64::from(1_u8).to_be_bytes();
with: example

code

but not working…If I need to update forc or sway, how do I do it?

What error are you getting? I am unable to reproduce an issue with your example or the follow below:

contract;

use std::{primitive_conversions::u64::*, bytes_conversions::u64::*};

abi MyContract {
    fn test_function() -> bool;
}

impl MyContract for Contract {
    fn test_function() -> bool {
        let my_u64 = u64::from(1_u8);
        let bytes = my_u64.to_be_bytes();

        let u64_value = u64::from(1_u8).to_be_bytes();
        
        true
    }
}
1 Like

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