5

I'm hitting an error when trying to do a cross contract call with two contracts running on substrate branch monthly-2022-03 and compiled with

    "language": "ink! 3.0.0-rc8",
    "compiler": "rustc 1.62.0-nightly"

The error is 'encountered error while calling ImportedContract::external_function: NotCallable'

The External Contract is imported as follows:

    /// Calls the `External` contract
    #[ink(message)]
    pub fn external_fn_wrapper(&self, accountid: AccountId, threshold: u8) -> bool {
        let mut external_instance: ExternalRef = ink_env::call::FromAccountId::from_account_id(self.external_account);
        external_instance.external_function(accountid, threshold).unwrap()
    }

The function that's trying to be cross-called in the External contract is public which I assume means it's callable.

        #[ink(message)]
        pub fn external_function(
            &mut self,
            user: AccountId,
            threshold: u8,
        ) -> Result<bool, Error> {

Does anyone have any ideas?

2 Answers 2

0

This error is emitted when the the address you specified is not callable. It has nothing to do with the messages defined within the contract. This usually means that either the address you specified is a tombstone or no contract at all (plain account).

That said, NotCallable is only used in older versions of the contracts pallet. New versions use the ContractNotFound error for this as tombstones are no longer a thing there.

-2

I think this was because I was calling a mutable function from a non-mutable function using a read. I changed the definition of external_function to be non-mutating, ran cargo clean in the cross calling contract, redeployed, and then it started to work.

        #[ink(message)]
        pub fn external_function(
            &self, // mut is gone
        ...

EDIT: This can also happen if your cached version of the contract from github is out of date. In this case, delete the cached version of the contract so that it is downloaded again.

e.g. delete this /usr/local/cargo/git/checkouts/THE-CONTRACT-9b59cb28149dd121/c56b619/contracts/lib.rs

2
  • This is wrong. NotCallable is emitted when the address being called is not a contract at all. Commented May 5, 2022 at 15:46
  • Both contracts were definitely deployed and I was receiving this message in the substrate debug when trying to perform a cross-contract call. 2022-05-04 13:41:19.688 DEBUG ThreadId(34) runtime::contracts: Execution finished with debug buffer: panicked at 'encountered error while calling External::external_function: NotCallable', /usr/local/cargo/git/checkouts/external-9b59cb28149dd121/c56b619/contracts/lib.rs:1046:9. Deleting this cached version is what fixed it for me.
    – forgetso
    Commented May 6, 2022 at 8:25

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.