I got an example running which deposits the Aave token into Aave. I'm using the Code Contracts examples provided by Aave v2 github

// Fork Kovan
await hre.network.provider.request({
    method: 'hardhat_reset',
    params: [{ forking: { jsonRpcUrl: KOVAN_JSON_RPC } }],

// Act like AAVE_HOLDER
await hre.network.provider.request({
    method: 'hardhat_impersonateAccount',
    params: [AAVE_HOLDER],
const signer = await hre.ethers.getSigner(AAVE_HOLDER);
console.log('signer:', signer.address);

// AAVE token on Kovan network
const aavetoken = IERC20__factory.connect(AAVE_TOKEN_ADDRESS, signer);
console.log('token balance:', (await aavetoken.balanceOf(signer.address)).toString());

const MyV2CreditDelegation = new MyV2CreditDelegation__factory(signer);
const delegation = await MyV2CreditDelegation.deploy({ gasLimit: 1e7 });
console.log('delegation:', delegation.address);

// Set the allowance higher than the deposit amount
// so we know we can make multiple transactions
let allowance = 100000
let despositAmount = 10;

await aavetoken.approve(delegation.address, allowance);
console.log('allowance:', (await aavetoken.allowance(signer.address, delegation.address, { gasLimit: 1e6 })).toString());

const depositTrans = await delegation.depositCollateral(aavetoken.address, despositAmount, true, { gasLimit: 1e6 });
console.log('depositTrans:', depositTrans.hash);
const depositReceipt = await depositTrans.wait();

Deposit works fine, However when I try to withdraw:

try  {
    var withdrawTrans = await delegation
        .withdrawCollateral(aavetoken.address,  { gasLimit: 1e6 })

    console.log('withdrawTrans:', withdrawTrans.hash);
    const withdrawReceipt = await withdrawTrans.wait();
catch (err) {
    console.log('Error:' + err);

I get an error:

Transaction reverted: function returned an unexpected amount of data

I'm pretty new to hardhat, I'm now sure of how to debug this any further. How can I withdraw from Aave?

1 Answer 1


I had the same error

Transaction reverted: function returned an unexpected amount of data

This happened when i called a function on an external contract that returns bytes32 and i assigned the return value to a variable of type bytes.


    function Func1() external returns (bytes memory returnValue) {   
        returnValue = Contract2(contract2.address).Func2();

On another Contract2

bytes32 Var = 0x5d73888975b842f81b854bb06846b539e34142cbcd3cc5e5e7ec53bafb8ed151;

    function Func2() external returns (bytes32 returnValue) {   
        return Var(;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.