I have a case here. Created a contract and sent some tokens to it. As of now, the contract is of not usable. The contract had destroy
function as below.
function destroy() onlyOwner {
// Transfer tokens back to owner
uint256 balance = token.balanceOf(this);
assert(balance > 0);
token.transfer(owner, balance);
}
But, when the token contract was created, the transfer
function was coded as below.
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
The line require(balanceOf[_to] + _value > balanceOf[_to]);
is not allowing to destory
as the require
always fails during send all the available tokens.
Had created another contract just test the drain function with a different name as below which worked properly. And the contract in consideration was not coded like this (that has the destroy function as above)
/**
* @notice Terminate contract and refund to owner
*/
function withdraw() onlyOwner external {
address myAddress = this;
if(myAddress.balance > 0)
owner.transfer(myAddress.balance);
uint256 tokBalance = token.balanceOf(this);
tokBalance = tokBalance - (1 wei);
if(tokBalance > 0)
token.transfer(owner, tokBalance);
}
Is there a way to burn/get back tokens from that contract? Though we can freeze the account, that doesn't help as we want to burn the tokens. Second contract (from where to withdraw or burn token) is here and 0x1798F533e0cE9501dac8a831A0b02A4f35304FFd is the address of it
require
is failing? Is the_to
account's balance overflowing?>=
in the condition? because of just>
this condition never met. I mean it supposed to berequire(balanceOf[_to] + _value >= balanceOf[_to]);
>=
is better, but only because ERC20 usually allows transfers of0
. It shouldn't cause a non-zero transfer to fail.