Say you have two account ids Aid(A) and Aid(B) and you want to combine them.e.g. XOR( Aid(A), Aid(B) ).

Basically, I want to achieve this;

T::Hashing::hash_of(&(idA, idB)) == T::Hashing::hash_of(&(idB, idA))

1 Answer 1


We can always represent types inside of the runtime as their encoded blobs (Vec<u8>), so this question breaks down to "How do you XOR two Vec<u8>"?

For that, I see this thread:


So a full solution would look like:

let idA: T::AccountId = account_a;
let idB: T::AccountId = account_b;

let mut bytesA: Vec<u8> = idA.encode();
let bytesB: Vec<u8> = idB.encode();

// `bytesA` is being modified in place.
// You could also allocate a new vector if you want.
    .for_each(|(x1, x2)| *x1 ^= *x2);

let new_account = T::AccountId::decode(bytesA)
        "all bytes are valid accounts, and the source of
        these bytes is the xor of two other accounts, thus
        this must also be a valid account. qed"
  • 1
    Very clear answer. Thanks Shawn! Feb 10, 2022 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.