Code NFT

How to withdraw the balance of a Solidity Smart Contract

If you’re working on an NFT project with a Solidity Smart Contract which allows people to pay for minting tokens (or other transactions) the value of the transaction will be added to your deployed contract.

Here’s a simple function to transfer the balance to the owner’s wallet – the contract here inherits from OpenZeppelin’s Ownable contract, to ensure only the owner of the contract can call this function.

function withdraw() external onlyOwner {
  address _owner = owner();