1

If I am the owner of a deployed smart contract, is it possible for me to withdraw the funds sent to the smart contract, without using any function ? I'm thinking of the case of a user sending tokens (or eth/bnb...) to the smart contract by error, then this could be a way for me to get his funds back and send them back to him.

2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Mar 21, 2022 at 10:25
  • Example : I deploy a smart contract (so I'm the owner). My smart contract is used for offering a staking program for ETH holders. The users send ETH to the smart contract to stake their ETH. But some users could probably send other type of assets to the smart contract (eg. tokens). I would like to be able to get the tokens back and to send them back to the users. Commented Mar 21, 2022 at 10:46

1 Answer 1

1

I don't think that is possible. Your contract would need a returnMoney() function or something like that for you to be able to do it.

The only other way I could see is if you had a private key of the said contract address. But I have never seen anything like that.

However, if your smart contract calls OtherContract and has a function that sets the address of the otherContract, you might be able to "hack yourself" (If you are the owner of the contract in the first place)

Example of what I am talking about:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./OtherContract.sol";

    contract MainContract is Ownable {
    
        /*
         * Imported SmartContracts
         */
        OtherContract OTHER;


         /**
         * @dev OtherContract the given Address (Sets the address for OtherContract.sol contract)
         *
         * @param addr OtherContract contract address
         */
        function setOtherContractAddress(address addr) public onlyOwner {
            OTHER = OtherContract(addr);
        }
7
  • 1
    Ok thank you. What you wrote is exactly what I think. I will try to find if there is a way to retrieve all tokens and all funds that are not tokens, from the smart contract, through a dedicated function. Commented Mar 21, 2022 at 10:43
  • 1
    Does your contract happen by any chance to have a function that calls another contract? It would help if I had the code of the smart-contract in question. Because there might be some workaround solutions (I can't promise anything, but it wouldn't hurt to have a look)
    – Sky
    Commented Mar 21, 2022 at 11:51
  • 1
    As far as I know, there is no way from a smart contract to know which ERC20 token have been received: you need to manage it offchain. To transfer tokens received by your smart contract, you can add a function calling ER20.approve which allow you to call ER20.transferFrom(your_contract, user, amount) Commented Mar 21, 2022 at 12:22
  • @PatriceTisserand Thank you but I wanted to know if there were a way without an existing function. But yes you are right. Commented Mar 22, 2022 at 10:09
  • 1
    @InvestDataSystemsFR Yes, there is a way, but only if your Initial contract has a function that can call another contract (And you can set the address for that other contract). The way I showed in the code above. But I would have to see the code of your contract to know more.
    – Sky
    Commented Mar 22, 2022 at 10:47

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.