Recommended way to estimate the fee required to send a message from an L1 contract to a Starknet contract?

219 Views Asked by At

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.

1

There are 1 best solutions below

5
Henri On

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_fee of which you can find an example here

Happy building!