GSN - Gas required exceeds allowance error on contract call

It has been deployed on Ropsten on 0xf3310e1D7d732D3700ecB5d13F07A566a6c98aA0. And I have the gas required exceeds allowance error when calling approve(“0xF5fe6280db283ba6975d72A3bD39bF57840433F7”, “1000000000000000000”)

pragma solidity ^0.5.3;

import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";

contract BancorInvest is Initializable, GSNRecipient {
  address private _owner;
  address public eth_token;
  address public bnt_token;
  address public converter;

  event ETHApproval(address indexed _owner, address indexed _spender, uint256 _value);
  event BNTApproval(address indexed _owner, address indexed _spender, uint256 _value);
  event Fund(address indexed _owner, uint256 _value);

  function initialise() public initializer {
    GSNRecipient.initialize();
    _owner = _msgSender();
    eth_token = address(0x62bd9D98d4E188e281D7B78e29334969bbE1053c);
    bnt_token = address(0xD368b98d03855835E2923Dc000b3f9c2EBF1b27b);
    converter = address(0xF5fe6280db283ba6975d72A3bD39bF57840433F7);
  }

  // accept all requests
  function acceptRelayedCall(
    address,
    address,
    bytes calldata,
    uint256,
    uint256,
    uint256,
    uint256,
    bytes calldata,
    uint256
  ) external view returns (uint256, bytes memory) {
    return _approveRelayedCall();
  }

  function owner() public view returns (address) {
    return _owner;
  }

  function _preRelayedCall(bytes memory context) internal returns (bytes32) {
  }

  function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
  }

  function setRelayHubAddress() public {
    if(getHubAddr() == address(0)) {
      _upgradeRelayHub(0xD216153c06E857cD7f72665E0aF1d7D82172F494);
    }
  }

  function getRecipientBalance() public view returns (uint) {
    return IRelayHub(getHubAddr()).balanceOf(address(this));
  }

  function approve(address _spender, uint256 _value) public
  {
    eth_token.call(abi.encodePacked("approve(address, uint256)", _spender, _value));
    emit ETHApproval(msg.sender, _spender, _value);
    bnt_token.call(abi.encodePacked("approve(address, uint256)", _spender, _value));
    emit BNTApproval(msg.sender, _spender, _value);
  }

  function fund(uint256 _amount) public
  {
    converter.call(abi.encodePacked("fund(uint256)", _amount));
    emit Fund(msg.sender, _amount);
  }
}
1 Like

Hi @leckylao,

I would test this manually (without using the GSN). Either using the OpenZeppelin CLI (if you deployed the contract with this) or using Remix etc to call the approve and fund functions.

For using the GSN with ERC20 tokens, both the ERC20 token (so that the holder can approve an allowance) and the contract using the token (so that the holder can call a function to do stuff) needs to be GSN enabled

Just tried to run with send-tx and transaction successful. But 2 internal transactions only one success. https://ropsten.etherscan.io/tx/0x289be462b25aad7f64cdbcede4248f4cc634479753d71b213cb924eedbc46f59

1 Like

Ah, Dann it. So it doesn’t work with existing token then…

1 Like

Hi @leckylao,

Unfortunately not. You would need some other mechanism to set the approval.