0

I have the following JS code to call a contract:

const txHash = await timelockContract.methods.executeTransaction(
      "0x71c1179e3C351De2641845cDAe537aCFC1808Fd2",
      0,
      "",
      "0x84e82a3300000000000000000000000000000000000000000000000000000000000003e800000000000000000000000031f2d666066d02953184ccb749946ed9a4a2218a00000000000000000000000000000000000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000000",
      1253215,
      ).send({from: "0xfa2c2284804D9Cb83BE7fEcCf7c171619F9915bF"}, (error, transactionHash) => {
        console.log(error);
        console.log(transactionHash);
    });

This way I encode the fourth parameter (encoded parameters to make call from smart contract to another one):

let b = web3.eth.abi.encodeFunctionCall({
    type: 'function',
    name: 'add',
    inputs: [
      {
        name: '1',
        type: 'uint256',
      },
      {
        name: '2',
        type: 'address',
      },
      {
        name: '3',
        type: 'uint16',
      },
      {
        name: '4',
        type: 'bool',
      },
    ],
  },
  [
    '1000',
    '0x9cBbdB6Ad6379D793ffa4Cb7A3643F3442f1836A',
    '200',
    false
  ]
);

This is the contract I'm calling (contract 1):

function executeTransaction(address 1, uint 2, string memory 3, bytes memory 4, uint eta) public payable returns (bytes memory) {
        emit Called("called");
 
        ...
       
        (bool success, bytes memory returnData) = 1.call{value: 2}(3);
        require(success, "Timelock::executeTransaction: Transaction execution reverted.");

        ...
    }

This contract calls another function in another contract (contract 2):

    function add(uint256 1, address 2, uint16 3, bool 4) public /*onlyOwnernonDuplicated*/ returns (bool) {
        
        
        IBEP20 token = IBEP20(2);
        
        uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
        totalAllocPoint = totalAllocPoint.add(3);
        poolExistence[_lpToken] = true;
        
        PoolInfo memory pI = PoolInfo({
            a : token,
            b : _allocPoint,
            c : lastRewardBlock,
            d : 0,
            e : _depositFeeBP
        });
        
        poolInfo.push(pI);

        return true;
    }

From executing the node.js script I get the following:

(node:154714) UnhandledPromiseRejectionWarning: Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x2b14a9d5c104775159962aa777439f8609b326e9c3ac092fdcd9c22030dffc4e",
  "blockNumber": 8006112,
  "contractAddress": null,
  "cumulativeGasUsed": 151440,
  "from": "0x96122617199a33fd297cbba77bec8eac0a745d67",
  "gasUsed": 99263,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0xbf37c65775baa015ee08ace1f4b301f0088efc77",
  "transactionHash": "0x5ec690d615ecd5eaf0e4b225b5dc9a185d80a3ba42983c99ff9627120377de74",
  "transactionIndex": 2,
  "events": {}
}
    at Object.TransactionError (/home/jordi/Projects/farm/goose-api/node_modules/web3-core-helpers/lib/errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (/home/jordi/Projects/x/node_modules/web3-core-helpers/lib/errors.js:98:21)
    at /home/jordi/Projects/x/node_modules/web3-core-method/lib/index.js:394:57
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:154714) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)

So the issue comes from contract 1 line:

require(success, "Timelock::executeTransaction: Transaction execution reverted.");

When debugging with truffle debug, I can see that the second contract is reached, and where it fails is at this line:

poolInfo.push(pI);

Seems like its failing when pushing the new object to the array.

So, when executing the same call in truffle console,(same call as in the nodejs script with exact same parameters), it works, I execute the following way:

t.executeTransaction("0x0b8Be1A0EE58cBb0db3e1Ea0bA7A788874a4C9d7", 0, "", "0x84e82a3300000000000000000000000000000000000000000000000000000000000003e800000000000000000000000094d06aa1e067230cc4edffab7e57174cd707298500000000000000000000000000000000000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000000", 1253215);

Executing the command above in the truffle console works perfectly fine. I compared both transactions, failed and succeeded when debuging, class state, local variables are both are the same.

I also deployed to BSC test net, same behaviour, from the node.js script it doesnt work, but from truffle console it works fine.

Appreciate any help, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.