How to retrieve tokens stuck in a crowdsale?

:memo:Details
I have created Crowdsale contract with PausableCrowdsale, AllowanceCrowdsale.
Some investors send other tokens then ETH to created contract address. I would like to give it back but without results. I wondering if it is possible ?

:1234: Code to reproduce
How I try do it via truffle on UNI tokens

deployerWallet = '0x...' /* main wallet address - creator of crowdsale */
from = '0x...' /* crowdsale contract address */
to = '0x ...' /* some client */

abi = JSON.parse('[{ ... abi copied from etherscan ...}]')
token_address = '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
contract = new web3.eth.Contract(abi, token_address)
amount = await contract.methods.balanceOf(from).call()

await contract.methods.transferFrom(from, to, amount).send({ from: deployerWallet })

after that the transaction has been created and stuck as pending. In from is deployerWallet, in Interacted With (To): is 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 (token_address). Without to field.


Crowdsale.sol

pragma solidity ^0.5.0 < 0.7.0;

import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/PausableCrowdsale.sol";

contract AwesomeCrowdsale is PausableCrowdsale, AllowanceCrowdsale {

  uint256 private _changeableRate;

  constructor(
    uint256 _rate,
    address payable _wallet,
    ERC20 _token,
    address _tokenWallet
  )
    Crowdsale(_rate, _wallet, _token)
    AllowanceCrowdsale(_tokenWallet)
    public
  {
    _changeableRate = _rate;
  }

    function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) {
      return weiAmount.div(_changeableRate);
    }
}

:computer: Environment
Truffle v5.1.42 (core: 5.1.42)
Solidity - 0.5.5 (solc-js)
Node v14.9.0
Web3.js v1.2.1
openzeppelin/contracts: 2.5.1

1 Like

Hi @herman-sadik,

Welcome to the community :wave:

Assuming you are still developing your crowdsale, you could add a function that transfers any tokens that have been accidentally transferred to the contract address.

You could use safeTransfer from the SafeERC20 wrapper.

If your crowdsale is already deployed then any tokens accidentally transferred to the contract address are stuck unless you have the above functionality.

1 Like

Hi, Thanks for your welcome :slight_smile:

Yep, this contract is already deployed and has no methods safe* implemented :confused:

I will remember that next time.
Thank You!

1 Like