Bitcoin core How do I get the transaction fee while using sendtoaddress
I think you want estimatesmartfee or estimatefee it takes one argument which is the confirmation target in blocks.  You can also select from Economical or Conservative fee modes which may affect the suggested fee rate.