Rust ink, cross contract call returns ConctractTrapped error

307 views Asked by At

As the title suggests, I'm trying to call a function on already deployed contract with a very simple String return function.

Deployed contract1 function:

#[ink(message)]
#[ink(selector = 0xDEADBEEF)]
pub fn test(&self) -> String {
            return "TEST".to_string()
}

The following code snippet is the contract2 function, to return the value from contract1:

        #[ink(message)]
        pub fn test1(&self,token_contract: AccountId) -> String {
            
            let my_return_value: String =  ink_env::call::build_call::<ink_env::DefaultEnvironment>()
            .callee(token_contract)
            .gas_limit(50000)
            .transferred_value(0)
            .exec_input(
                ink_env::call::ExecutionInput::new(ink_env::call::Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
                

            )
            .returns::<ink_env::call::utils::ReturnType<String>>()
            .fire()
            .unwrap();
            my_return_value
        }
1

There are 1 answers

0
themartto On BEST ANSWER

This means that your sub contract, the one that is holding "pub fn test" has panicked.

The way to debug this is to start your substrate node with:

RUST_LOG=runtime=debug

This way you'll get the exact panic error in the substrate logs.

If you wish to handle the error in your caller contract build_call has map_err function. You can check their multisig example for code reference: https://github.com/paritytech/ink/blob/master/examples/multisig/lib.rs