Fail with error 'SafeERC20: low-level call failed when deposit to Aave v2

Expert

Hi,I need help, I try to depoist to Aave lending pool v2 contract from my contract,but fail .

Fail info Fail with error 'SafeERC20: low-level call failed

pragma solidity *@.6.12;
import "https://github.com/aave/protocol-v2/blob/ice/mainnet-dep Loyment-03-12-2020/contracts/protocol/lendingpool/Lendir

contract MyDeposit{l
LendingPool public lendingPool;
address public myUSDCaddress;

constructor() public {
lendingPool = LendingPool(0x4bd5643ac6f66a5237E18bfA7d47cF22f1c9F210) 5
myUSDCaddress = @x9FD21bE27A2B0@59a288229361E2fA632D8D2d074;

function deposit(uint256 _amount) public{

lendingPool.deposit(myUSDCaddress, _amount, 0x9041a80B8fB42f1A2858698925A48EDA268b224A, @) ;

Answers 2

Based on the error message you received, it seems like the issue is related to the SafeERC20 library. The error message indicates that a low-level call failed, which may be caused by an issue with the transfer or transferFrom function from the SafeERC20 library.

Here are some possible solutions to this issue:

Make sure that you have approved the LendingPool contract to spend your USDC tokens. You can do this by calling the approve function on the USDC token contract before calling the deposit function on the LendingPool contract.

Check that the address of the USDC token contract and the LendingPool contract are correct.

Ensure that you are passing the correct arguments to the deposit function. The amount parameter should be in the smallest unit of the token (e.g., for USDC, this would be 6 decimal places), and the onBehalfOf parameter should be set to the address that will receive the deposited funds.

Verify that your contract has enough balance of USDC to deposit.

You can use tenderly.io to debug the failed transaction, but it's most likely that your contract is not approved to spend the user's USDC.