Web3 abi.encodeFunctionCall doesn't work for two function calls in one transaction

Ok. Here is my next question. Not related to OpenZeppelin. But, I am unable to solve this yet past 2 days.

I am trying to execute deposit and withdraw function from yDAI (yearn.finance) within the same transaction using web3 encodeFunctionCall. deposit function works, but, withdraw function fails. However, if I execute the withdraw function alone separately, then it works.

let abi1 = web3.eth.abi.encodeFunctionCall( { "name": "deposit", "type": "function", "inputs": [ { "name": "_amount", "type": "uint256" } ] }, [web3.utils.toWei((1000).toString(), 'Ether')] );

let abi2 = web3.eth.abi.encodeFunctionCall( {"constant":false,"inputs":[],"name":"withdrawAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}, [] );

I am encoding the above in a js file and then calling a function present in my smart contract using an array. Code present in smart contract:

for (uint i = 0; i < _addrs.length; i++)

There are no error messages.

Here is the code and abi for yDAI (yearn.finance) .

Can anyone help me to solve this puzzle?


By the way, I am using ganache mainnet fork with truffle. May be its a bug in this setup? May be it will work in mainnet? Unfortunately, I cannot test this on public testnets like ropsten. I am scared to test it in mainnet cause, I will loose some eth for gas. So, how to solve this?

1 Like

Ok. I burnt some heavy ether GAS and I tested this on mainnet. It works there. So, this is an issue with the ganache mainnet fork setup. I cant believe I wasted 3 days on this just to find out that the same code works fine on mainnet. This is scary to me for what I want to achieve. If something did not work on ganache mainnet fork setup how can I be sure that its NOT the issue with the setup itself?

Anyway, I have to accept this and move on.

Just wanted to let you people know about this if in case someone is stuck like me testing the code in ganache mainnet fork setup.


1 Like

Hi @harishbp,

Sorry to hear that you had issues with ganache fork of mainnet which didn’t actually occur on mainnet itself. That is not fun.

It may be worth asking in the Truffle Gitter: https://gitter.im/ConsenSys/truffle