I write tests for my smart contract and got this error:

no caller has been set

The error comes from: ink_engine-4.2.0/src/ext.rs:325:14. In function that I want to write tests I have following line:

let caller = self.env().caller();

Any suggestion what I do wrongly?

I look at the place the error comes from, and I see following code:

/// Returns the address of the caller.
pub fn caller(&self, output: &mut &mut [u8]) {
    let caller = self
        .expect("no caller has been set")
    set_output(output, caller);
  • here are the function needed while writing test in ink! smart contract. You need to set_caller like this
    – go11li
    Jun 8, 2023 at 1:13

1 Answer 1


I think that this is not ideal solution, but working.

let _accounts = ink_env::test::default_accounts::<ink_env::DefaultEnvironment>();
let contract_addr: AccountId = AccountId::from([0xFF as u8; 32]);

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.