I am using Polygon mainnet. Below are the steps I am trying to follow.

address private constant _lendingPoolAddressesProvider = 0xd05e3E715d945B59290df0ae8eF85c1BdB684744;
address private constant USDC_POLY_ADDRESS = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;

ILendingPoolAddressesProvider addressesProvider = ILendingPoolAddressesProvider(_lendingPoolAddressesProvider);
ILendingPool lendingPool = ILendingPool(addressesProvider.getLendingPool());

uint16 referralCode = 0;

function deposit(uint256 amount, address to) external {
    require(amount > 0, "Amount needs to be greater than 0");

    // Transfer USDC to this contract
    usdc.transferFrom(msg.sender, address(this), amount);

    // Approve contract to deposit it into the lendingPool
    usdc.increaseAllowance(address(lendingPool), amount);

    // Actually deposit into the lendingPool on behalf of the to address
    lendingPool.deposit(address(usdc), amount, to, referralCode);

function withdraw(address to) external {
    lendingPool.withdraw(address(usdc), type(uint).max, to);

The deposit function is working fine but the withdraw function is failing. https://polygonscan.com/tx/0x9621fdfe18ed2c634a2ed4b5c2c9e139968519a5ca9036a3fa0e1e8d10d8c97b

Can someone please help decode this.


  • you have not deposited, while checking your contract the only two things you did were deploy and withdraw polygonscan.com/address/…
    – Adam Boudj
    Apr 6, 2022 at 18:27
  • The to address I'm using in the withdraw has already used the deposit method and deposit some funds into aave in a separate transaction Apr 12, 2022 at 11:12


Your Answer

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

Browse other questions tagged or ask your own question.