Bitcoin core How do I get the transaction fee while using sendtoaddress I have a bitcoin core running on testnet, so for suppose I have a wallet balance of 1BTC and I have to send it to an addressx, so how can I know the amount of transaction fee so that I can subtract it from the sending amount.

bitcoin-cli sendtoaddress x 1


This will return an error stating that 

error code: -4
error message:
Error: This transaction requires a transaction fee of at least 0.00000488


How can I know it beforehand the fee required for a transaction?
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.