Contract runs without problems on Ethereum(Ganache), but not Quorum

Hi community,
I deployed this contract:

pragma solidity ^0.5.5;

import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract TokenExchange {

    using SafeMath for uint256;

    address private _owner;

    // Contract constructor: set owner
    constructor() public {
        _owner = msg.sender;
    }

    // Access control modifier
    modifier ownerOnly {
        require(msg.sender == _owner,
            "Only the contract owner can call this function");
        _;
    }

    function swapTokens(
        address sourceTokenCA,
        address sourceEOA,
        uint256 sourceTokenValue,
        uint sourceTokenType,
        address targetTokenCA,
        address targetEOA,
        uint256 targetTokenValue,
        uint targetTokenType,
        address exchangeCA
    ) public ownerOnly returns (bool) {
        bool success = false;

        if (_transferFrom(sourceTokenCA, sourceEOA, exchangeCA, sourceTokenValue, sourceTokenType) &&
            _transferFrom(targetTokenCA, targetEOA, exchangeCA, targetTokenValue, targetTokenType) &&
            _transfer(sourceTokenCA, targetEOA, sourceTokenValue, sourceTokenType) &&
            _transfer(targetTokenCA, sourceEOA, targetTokenValue, targetTokenType)
        ) {
            success = true;
        }

        return success;
    }

    function _transferFrom(
        address tokenCA,
        address EOA,
        address exchangeCA,
        uint256 value,
        uint tokenType
    ) internal returns (bool) {
        bool rtnVal = false;

        if(tokenType == 20 || tokenType == 721) {
            (bool success, bytes memory result) = address(tokenCA).call(
                abi.encodeWithSignature("transferFrom(address,address,uint256)", EOA, exchangeCA, value)
            );
            rtnVal = success;
        }

        if(!rtnVal) {
            revert();
        }

        return rtnVal;
    }

    function _transfer(
        address tokenCA,
        address EOA,
        uint256 value,
        uint tokenType
    ) internal returns (bool) {
        bool rtnVal = false;

        if(tokenType == 20 || tokenType == 721) {
            (bool success, bytes memory result) = address(tokenCA).call(
                abi.encodeWithSignature("transfer(address,uint256)", EOA, value)
            );
            rtnVal = success;
        }

        if(!rtnVal) {
            revert();
        }

        return rtnVal;
    }

}

Deployment goes fine, I use remix on a Quorum private blockchain.
The issue after, when trying to interact with this contract:

  • If try to execute a transaction on this contract, for instance calling swapTokens() function to start swapping erc20 tokens…I get this error:
    status false Transaction mined but execution failed transaction hash 0x7356c4820605b0c15f13525028c5a27b9c1bac56657db7dff18ee2aebbc0f837 from 0x079d713C8490e468Cc2680D7430e301782d597e8 to TokenExchange.swapTokens(address,address,uint256,uint256,address,address,uint256,uint256,address) 0x0B052dE6ce9066e19826383cdEEeDE4788f3c3E6 gas 3000000 gas transaction cost 3000000 gas hash 0x7356c4820605b0c15f13525028c5a27b9c1bac56657db7dff18ee2aebbc0f837 input 0x90a...3c3e6 decoded input { "address sourceTokenCA": "0x804B4D280C0b34d2CD110af154De289F14ba1B02", "address sourceEOA": "0x079d713C8490e468Cc2680D7430e301782d597e8", "uint256 sourceTokenValue": { "_hex": "0x01" }, "uint256 sourceTokenType": { "_hex": "0x14" }, "address targetTokenCA": "0xC81D113776ecbfd52c7c9de46c6ee848637DE99D", "address targetEOA": "0xcc83Fd1b198EBc44D947608283Dd3834fC746a87", "uint256 targetTokenValue": { "_hex": "0x02" }, "uint256 targetTokenType": { "_hex": "0x14" }, "address exchangeCA": "0x0B052dE6ce9066e19826383cdEEeDE4788f3c3E6" } decoded output - logs [] value 0 wei
1 Like

Hi @MoonyongPark,

Welcome to the community :wave:

My first thought is that EVM version could be the issue.

I recommend checking what EVM version Quorum supports and you can then set the EVM version in Remix to this value.
https://solidity.readthedocs.io/en/v0.5.17/using-the-compiler.html
https://remix-ide.readthedocs.io/en/latest/compile.html#compiler-solidity

As an aside, you may want to use IERC20 (or even SafeERC20) and IERC721 for the transfers.

You also appeared to be transferring from the source to the exchange and then to a target, when you could transfer from source to target.

Hi @MoonyongPark,

Just checking if you were able to resolve by changing the EVM version?