I want to write a function that would withdraw all the Ether from the contract:

function withdraw() {
  1. Should I consider here subtracting the (gas-cost * gas-price) from the address(this).balance, or is it going to get paid from the one's address, who called the function?

  2. If I have to calculate (gas-cost * gas-price), how could I do it using pure Solidity?

Thank you

1 Answer 1


Since gas usage is a factor outside the contract, it cannot be calculated within the contract. The account that called the function (EOA) pays for gas. It is not paid by the contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.