Smart contract calling a CIS2 smart contract: compile error of host.invoke in a loop

Hi,

I’m trying to call a mint function of a CIS2 contract instance within another contract instance. Due to the limit of the CIS2 mint, see below note, I need to split the tokens (if more than 32) I have in another contract so that I can invoke the CIS2 mint without getting due to the limitation. This means that I need to loop through split tokens and then call host.invoke. But of course the borrow checker doesn’t allow borrow of mutable host more than once so I’m getting a compile error in the loop. Any way to circumvent this?

“/// Note: Can at most mint 32 token types in one call due to the limit on the
/// number of logs a smart contract can produce on each function call.”

The compile error (cannot borrow *host as mutable more than once at a time
) is in the arrow below:

for chunk in nft_mintable_chunks {
→ host.invoke_contract(
&nft_contract_address_here,
&to_bytes(&mint_params),
nft_mint_receive_fn.as_entrypoint_name(),
Amount::zero(),
).unwrap_abort();
}

Hello ulapcyber

We will get back to you ASAP.

Regards,
Concordium Tech Support

Calling host.invoke_contract(..) in the loop should not give you any problems by itself.
So maybe something before the loop is holding a mutable reference to the host.
Do you use host anywhere before the loop?

You should know that starting from protocol version 5 (effective on mainnet since Dec 13 2022) the limit on the number of logs was removed, so it might save you the trouble

1 Like

Thanks limemloh. Yes, there was something before the loop that I failed to check so my bad. And thanks for pointing the removal of the limitation in protocol 5. :slight_smile: