Skip to content

Instantly share code, notes, and snippets.

@Mc01
Created January 29, 2024 16:51
Show Gist options
  • Save Mc01/8f5c9106cfea0f64d6254d60f1240353 to your computer and use it in GitHub Desktop.
Save Mc01/8f5c9106cfea0f64d6254d60f1240353 to your computer and use it in GitHub Desktop.
[Substrate] Convert string to AccountId
use bs58;
#[inline]
pub fn convert_string_to_accountid(account_str: &str) -> AccountId {
let mut output = vec![0xFF; 35];
bs58::decode(account_str).onto(&mut output).unwrap();
let cut_address_vec: Vec<_> = output.drain(1..33).collect();
let mut array = [0; 32];
let bytes = &cut_address_vec[..array.len()];
array.copy_from_slice(bytes);
let accountId: AccountId = array.into();
accountId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment