I am trying to call an extrinsic with specific AccoundId, I have considered two options

  1. Generate AccountId from Key-Pair
    let caller = sr25519::Pair::from_string("//1", None)
  2. Hardcode accountId
    let caller:T::AccountId = "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o".to_owned().into()

Generating the same AccoundId is important because there is an Origin check in extrinsic that AccountId should exit in Some_Storage of type Vec<T::AccountId>

benchmarks! {
    set_value {
    let caller = sr25519::Pair::from_string("//1", None).unwrap();
    }: _(RawOrigin::Signed(caller.public().into()),2)

Is there any way to generate AccountId from the above two ways or any other way? Any help or advice is appreciated.

1 Answer 1


Yes you can use the frame_benchmarking::account function to derive accounts deterministically.
It is possible to vary them with a seed, if needed.

use frame_benchmarking::{account, whitelist};

const SEED: u32 = 1;

benchmarks! {
    set_value {

        let caller: T::AccountId = account("Alice", 0, SEED);

    }: _(RawOrigin::Signed(caller), 2)

The whitelist macro invocation is important to make the signing part work.
Otherwise if you just need a fixed account, you can use the whitelisted_caller account.

  • I want to generate the same AccountId generated by pair, so basically I will need to convert sr25519::Public to AccountId.
    – salman01z
    Mar 30, 2022 at 11:16
  • 1
    AccountId is normally just a u64 for benchmarking, so that is not possible AFAIK. Can you not just insert the AccountId into the storage with Some_Storage::<T>::append(id)? Mar 30, 2022 at 15:36
  • yeah, for now, I am referring to it from the storage. Thanks
    – salman01z
    Mar 30, 2022 at 17:18

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.