2

Getting this error while trying to build an Ink! contract with a message accepting a reference argument

   |
95 |         pub fn some_message(&self, account_id: &AccountId) -> bool {
   |                                                    ^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter

Adding a named lifetime parameter (as suggested by compiler) doesn't help either:

error: ink! messages must not be generic
  --> /home/greez/dev/polkadot/ink/examples/is-contract/lib.rs:95:29
   |
95 |         pub fn some_message<'a>(&self, account_id: &'a AccountId) -> bool {
   |                             ^^

error: could not compile `is_contract` due to previous error

1 Answer 1

5

The reason for this issue is that currently Ink! messages and constructors are not allowed to take simple references as arguments, as they are required to be Sized and scale::Decode.

Until this has been improved (see this tracking issue), possible workaround could be to add private methods that take their arguments as references, to call them from inside messages or constructors.

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.