# How to convert principal to account id in rust

**URL:** <https://forum.dfinity.org/t/how-to-convert-principal-to-account-id-in-rust/7376>\
**Category:** Developers\
**Created:** [September 18, 2021, 6:34pm UTC](https://forum.dfinity.org/t/how-to-convert-principal-to-account-id-in-rust/7376 "2021-09-18T18:34:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayazgv](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ayazgv/32/1587_2.png) [@ayazgv](https://forum.dfinity.org/u/ayazgv)\
**Post date:** [September 18, 2021, 6:34pm UTC](https://forum.dfinity.org/t/how-to-convert-principal-to-account-id-in-rust/7376/1 "2021-09-18T18:34:29Z")

</div>

Hello Dears!

Is it possible to convert principal to account id?  
if yes, then how can I do that in rust?

---

<div class="post-metadata">

**Author:** ![GLdev](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@GLdev](https://forum.dfinity.org/u/GLdev)\
**Post date:** [September 18, 2021, 7:03pm UTC](https://forum.dfinity.org/t/how-to-convert-principal-to-account-id-in-rust/7376/2 "2021-09-18T19:03:20Z")

</div>

What do you mean by account id? Do you mean the anchor id that you create with the Internet Identity canister? That is private, and AFAIK cannot be inferred from the principal.

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [September 18, 2021, 7:11pm UTC](https://forum.dfinity.org/t/how-to-convert-principal-to-account-id-in-rust/7376/3 "2021-09-18T19:11:17Z")

</div>

For now, you can copy this file [ic-repl/account\_identifier.rs at master · chenyan2002/ic-repl · GitHub](https://github.com/chenyan2002/ic-repl/blob/master/src/account_identifier.rs) to your project and use `AccountIdentifier::new(principal, None)` to get the account id.

Eventually, we want to put this into the `ic-type` crate to avoid code duplication.
