SafeERC20: low-level call failed

Hello, I want to send an ERC-20 Token to a contract and then be able to execute a withdraw method on behalf of the contract owner.

I'd like to be able to send some token to any beneficiary address of my choosing.

I am currently able to send tokens to my own ( contract creator address ) when I execute this method with web3, however it gives me an error "SafeERC20: low-level call failed" Whenever I try to send tokens to a different address that does NOT belong to the contract creator.

here is my contract code:

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.5.11;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import '@openzeppelin/contracts/math/SafeMath.sol';
import '@openzeppelin/contracts/ownership/Ownable.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';


/**
 * @title MyPlayContract
 */
contract MyPlayContract is ReentrancyGuard, Ownable {

    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    IERC20 private _token;

    event Received(address, address, uint256);

    constructor (IERC20 token) public {
        require(address(token) != address(0), "MyPlayContract: token is the zero address");
        _token = token;
    }

    function withdraw(address token, address recipient, uint256 amount) public onlyOwner {
        IERC20(token).safeTransfer(recipient, amount);
    }
}

My web3 code uses a private key to execute this contract on behalf of the owner of the contract.

ALSO:: This issue only happens on the BSC Mainnet and Works fine on the TestNet

Any help would be greatly appreciated!

are you calling the function with the address that deployed the MyPlayContract contract? In your first line, you said

Hello, I want to send an ERC-20 Token to a contract and then be able to execute a withdraw method on behalf of the contract owner.

The withdraw() function can only be called by the contract owner because of the onlyOwner() modifier.

2 Likes