Skip to main content
deleted 1 character in body
Source Link
aurexav
  • 11.2k
  • 6
  • 33

JS encode:

const registry = new TypeRegistry();
const someNameInstance = registry.createType('{"current_fraction":"u32"}', { current_fraction: 123 });
    const encoded = someNameInstance.toU8a();

console.log('Encoded:', encoded);
// Encoded: Uint8Array(4) [ 123, 0, 0, 0 ]

Rust decode:

#[derive(Debug, Decode)]
pub struct SomeName {
    pub current_fraction: u32,
}

println!("{:?}", SomeName::decode(&mut [123, 0, 0, 0].as_slice()));
// Ok(SomeName { current_fraction: 123 })

JS encode:

const registry = new TypeRegistry();
const someNameInstance = registry.createType('{"current_fraction":"u32"}', { current_fraction: 123 });
    const encoded = someNameInstance.toU8a();

console.log('Encoded:', encoded);
// Encoded: Uint8Array(4) [ 123, 0, 0, 0 ]

Rust decode:

#[derive(Debug, Decode)]
pub struct SomeName {
    pub current_fraction: u32,
}

println!("{:?}", SomeName::decode(&mut [123, 0, 0, 0].as_slice()));
// Ok(SomeName { current_fraction: 123 })

JS encode:

const registry = new TypeRegistry();
const someNameInstance = registry.createType('{"current_fraction":"u32"}', { current_fraction: 123 });
const encoded = someNameInstance.toU8a();

console.log('Encoded:', encoded);
// Encoded: Uint8Array(4) [ 123, 0, 0, 0 ]

Rust decode:

#[derive(Debug, Decode)]
pub struct SomeName {
    pub current_fraction: u32,
}

println!("{:?}", SomeName::decode(&mut [123, 0, 0, 0].as_slice()));
// Ok(SomeName { current_fraction: 123 })
Source Link
aurexav
  • 11.2k
  • 6
  • 33

JS encode:

const registry = new TypeRegistry();
const someNameInstance = registry.createType('{"current_fraction":"u32"}', { current_fraction: 123 });
    const encoded = someNameInstance.toU8a();

console.log('Encoded:', encoded);
// Encoded: Uint8Array(4) [ 123, 0, 0, 0 ]

Rust decode:

#[derive(Debug, Decode)]
pub struct SomeName {
    pub current_fraction: u32,
}

println!("{:?}", SomeName::decode(&mut [123, 0, 0, 0].as_slice()));
// Ok(SomeName { current_fraction: 123 })