Is there a way to know beforehand the amount of energy needed when invoking a sender method of a deployed smart contract?
No, this is not possible directly.
You could look at the history of the same invocation to get an estimate.
However the intended way to estimate the NRG cost before sending the transaction is to use the InvokeContract
endpoint. This will essentialy dry-run the transaction and return the result, and the NRG cost.
Using concordium-client
this endpoint is available under contract invoke
command (in contrast to contract update
, which sends a transaction)