1

I have replicate this error using the MultiContractCaller from the ink-examples

In the multi_contract_caller we have a FakeEvent.

#[ink(event)]
pub struct FakeEvent {
    account_id: AccountId,
}

Which is being emitted in the multi_contract_caller change

#[ink(message)]
pub fn change(&mut self, by: i32) {
     let caller = self.env().caller();
     self.env().emit_event(FakeEvent { account_id: caller });
     match self.which {
           Which::Adder => self.adder.inc(by),
           Which::Subber => self.subber.dec(by),
    }
}



In the accumulator we have another FakeEvent.

#[ink(event)]
pub struct FakeEvent {
    account_id: AccountId,
}

Which is being emitted in the accumulator inc

#[ink(message)]
pub fn inc(&mut self, by: i32) {
       let caller = self.env().caller();
       self.env().emit_event(FakeEvent { account_id: caller });
       self.value += by;
}

In theory this should have been solved by the "Events 2.0"

But the result is this below. Nevertheless, anyone knows why or what magic trick should I do to make this work?

error[E0284]: type annotations needed
   --> /home/projects/crap/ink-examples-main/multi_contract_caller/lib.rs:101:24
    |
101 |             self.env().emit_event(FakeEvent { account_id: caller });
    |                        ^^^^^^^^^^
    |
    = note: cannot satisfy `<_ as ContractEventBase>::Type == _`
help: try using a fully qualified path to specify the expected types
    |
101 |             <EnvAccess<'_, DefaultEnvironment> as EmitEvent<C>>::emit_event::<FakeEvent>(self.env(), FakeEvent { account_id: caller });
    |             +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++          ~

error[E0283]: type annotations needed
   --> /home/projects/crap/ink-examples-main/multi_contract_caller/lib.rs:101:24
    |
101 |             self.env().emit_event(FakeEvent { account_id: caller });
    |                        ^^^^^^^^^^
    |
note: multiple `impl`s satisfying `EnvAccess<'_, DefaultEnvironment>: EmitEvent<_>` found
   --> /home/projects/crap/ink-examples-main/multi_contract_caller/lib.rs:3:1
    |
3   | #[ink::contract]
    | ^^^^^^^^^^^^^^^^
    = note: and another `impl` found in the `accumulator` crate: `impl<'a> EmitEvent<Accumulator> for EnvAccess<'a, <Accumulator as ContractEnv>::Env>;`
    = note: this error originates in the attribute macro `ink::contract` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try using a fully qualified path to specify the expected types
    |
101 |             <EnvAccess<'_, DefaultEnvironment> as EmitEvent<C>>::emit_event::<FakeEvent>(self.env(), FakeEvent { account_id: caller });
    |             +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++          ~

Some errors have detailed explanations: E0283, E0284.
For more information about an error, try `rustc --explain E0283`.
error: could not compile `multi_contract_caller` (bin "multi_contract_caller") due to 2 prevERROR: command ["/home/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo", "build", "--color=always", "--target=wasm32-unknown-unknown", "-Zbuild-std=core,alloc", "--no-default-features", "--release", "--target-dir=/home/projects/crap/ink-examples-main/multi_contract_caller/target/ink", "-Zbuild-std-features=panic_immediate_abort"] exited with code 101

Whit this bug there are at least two other posts:

Post I

Post II

1
  • 4.2.1 ink doesn't contains the change you mentioned (neither events 2.0) can you try your reproducible bug example with ink! from mater and see if it works ?
    – P.Ossun
    Aug 18 at 11:44

1 Answer 1

3

Why don't you do exactly what error message states? Replace

self.env().emit_event(FakeEvent { account_id: caller });

with

use ink::{
  codegen::EmitEvent,
  env::DefaultEnvironment,
  EnvAccess,
};

<EnvAccess<'_, DefaultEnvironment> as EmitEvent<MultiContractCaller>>::emit_event::<FakeEvent>(
  self.env(),
  FakeEvent { account_id: caller },
);

I am not sure why error happened but following error message instructions helped me to solve the same error in contract I wrote some time ago.

4
  • Hi, @Bobo K. That was the first thing that I did. Probably my compiler is busted.... :(
    – Evil Kyle
    Aug 18 at 13:17
  • 1
    It might be your local env issue since I can compile your contract with the changes above
    – Bobo K.
    Aug 18 at 13:25
  • Thanks a lot for your trouble @Bobo K. I own you a beer...
    – Evil Kyle
    Aug 18 at 13:29
  • 1
    I was able to compile this contract in another machine so this is the right answer.
    – Evil Kyle
    Aug 18 at 13:39

Your Answer

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

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