Regarding this topic of holding tokens inside a smart contract, if the allowed withdrawer transfers the tokens out sending it to another address who pays for the gas fees? Do we have to create a payable function first so the smart contract can accept ETH which will be used for Gas purposes? Or whoever performs the function to withdraw pays for the gas fees?
Hi @Benjamin_P,
Which ever account initiates the transaction pays with gas.
Looking at the following example, you could have access control so only an admin account could withdraw tokens and they could ask to be compensated prior to withdrawing.
Got it. If in case I don’t put any restrictions on withdrawal, does it mean anyone can withdraw the tokens inside the contract? If I don’t put a withdraw function, will there be any way to withdraw the tokens using the built-in functions like transfer or transferFrom?
Hi @Benjamin_P,
If there is no access control, then anyone can withdraw tokens held by the contract.
If there isn’t a withdraw function (or other functionality to transfer tokens held by the contract) then tokens held by the contract are essentially locked.
So you mean there is no standard that can be used to include a withdrawal of tokens from the contract and that we really have to create a withdraw function by ourselves just like the one you showed on the other post?
Hi @Benjamin_P,
There isn’t an extension in OpenZeppelin Contracts to withdraw tokens from a contract. Mostly due to the various use cases. e.g. a contract may have valid reasons for holding tokens such as a Crowdsale.
If you wanted to implement this functionality, you may want to see how other projects have done this.
Thanks for the response.