title: How to withdraw the current balance of the smart contract using web3.py?
body: <p>I have already created a function for doing so in solidity, but in the frontend, I want to be able to call that function and transfer ether from the contract to an account. Here is the code from solidity.</p>
  <pre><code>    function withdraw() public payable onlyOwner {
          payable(msg.sender).transfer(address(this).balance);
      }
  </code></pre>
  <p>So far, for calling other functions that involve a state change I have used build transaction from web3.py. In order to transfer ether to the contract, I have done this -</p>
  <pre><code>booking_contract = w3.eth.contract(address=self.receipt.contractAddress, abi=abi)
          nonce = w3.eth.getTransactionCount(address)
          booking_transaction = booking_contract.functions.book(machine_name, start_time, end_time).buildTransaction(
              {
                  &quot;chainId&quot;: chain_id,
                  &quot;gasPrice&quot;: w3.eth.gas_price,
                  &quot;from&quot;: address,
                  &quot;nonce&quot;: nonce,
                  &quot;value&quot;: 100
              }
          )
          signed_txn = w3.eth.account.sign_transaction(booking_transaction, private_key=key)
          txn_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
  </code></pre>
  <p>Is there any way to transfer the ether sent to the contract here to any account I want?</p>