I'm sending a message from an Ethereum contract to a Starknet one via the Starknet core contract's sendMessageToL2 function. This function is payable and I'm meant to send ETH to cover the cost of processing the message at the other end. What I don't know is how to estimate the amount of ETH required, which could vary from one call to another, as the processing required on the receiving Starknet contract will vary.
I have searched the docs, but didn't find anything on this. Until recently everything worked with no fee being sent, but that has been tightened up now.
You can use Starknet's cli to call a function called
estimate_message_fee. See it here. It will tell you how much you should attach to your message.Under the hood, it is called Starknet's feeder gateway API with the same name "estimate_message_fee". You can also call this one directly. The call should be similar to
estimate_feeof which you can find an example hereHappy building!