• I want to convert the address string received as a parameter to an ink! AccountId.
  • I have implemented the following source code using sp-runtime. When I implemented the following in pallet, it worked, but in ink!, the type of AccountId is different and I can't compile it.
  • Please tell me how to convert the string address to AccountId in "ink!".
        fn convert_vec_to_accountid(&self, account_vec: Vec<u8>)-> AccountId{ 
          let mut array = [0; 32];
          let bytes = &account_vec[..array.len()]; 
          let account32: AccountId32 = array.into();
          let mut to32 = AccountId32::as_ref(&account32);
          let to_address : AccountId = AccountId::decode(&mut to32).unwrap_or_default();
  • Why do you want to parse a String to an AccountId exactly?
    – rajohs
    Sep 12, 2022 at 22:19

1 Answer 1

  • I read the account page on the polkadot wiki and implemented the following logic.
  • I've tested it and it's working fine at the moment.
  • However, I don't understand enough to explain this structure to someone.
  • So be careful when using this logic.
  • Or if anyone can give me the correct logic, detailed explanation, please help me. https://wiki.polkadot.network/docs/learn-accounts
        fn convert_string_to_accountid(&self, account_str: &str)-> AccountId{
            let mut output = vec![0xFF; 35];
            bs58::decode(account_str).into(&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()]; 
            let accountId:AccountId = array.into();

Your Answer

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

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