Skip to content
Advertisement

Supply ETH to Aave through solidity

I’m trying deposit into Aave V2 Contract Aave’s Code Examples

JavaScript

I have code which consumes this like so:

JavaScript

When attempting to supply, Metamask displays an error:

ALERT: Transaction Error. Exception thrown in contract code.

And just a simple button to call it in html:

JavaScript

I’m running ganache

ganache-cli --fork https://mainnet.infura.io/v3/{{MyProjectId}}

The only error I see in the console is:

Transaction: 0x9961f8a187c09fd7c9ebf803771fa161c9939268bb01552a1598807bcfdc13ff Gas usage: 24813 Block Number: 12905002 Block Time: Mon Jul 26 2021 20:38:30 GMT-0400 (Eastern Daylight Time) Runtime Error: revert

My guess is that I’m not calling the contract from Web3 appropriately

How can programatically supply Eth (Or any other token) to aave?

Advertisement

Answer

I used Hardhat to send transactions instead of Web3 in the browser, but I succeeded:

  • I used the Kovan test network.
  • I used the MyCrypto faucet to give my test address some ETH.
  • I used the Aave faucet to give myself some AAVE.
  • I imported the contracts from Aave’s Code Examples.
  • I ran the script below:

Create a new HardHat project

JavaScript
JavaScript

With as result:

JavaScript

Which you can verify on Etherscan for Kovan (blocks 26666177, 26666180 and 26666183):

  • Deploying MyV2CreditDelegation (transaction, contract)
  • Approving contract for AAVE (transaction)
    • Logged Approval event and token.allowance returned correct value
  • Depositing collateral (transaction)
    • Transferred 0.000001 AAVE from my address to deployed contract
    • Transferred 0.000001 aAAVE from my address to deployed contract
    • Transferred 0.000001 AAVE from deployed contract to aAAVE contract
    • Bunch of logged events for Transfer/Approval/Mint/DelegatedPowerChanged/…

Originally my script would first deploy a test token (and mint me some balance on it) which I would try to deposit as collateral, but the provider somehow reverted it without a transaction even showing up on Kovan Etherscan. The issue in your code might thus be the mockETHAddress, as well as it seems like you’re not actually approving your delegation contract to withdraw the specified amount.

A more complex but ready-to-run setup is available in this repository. It impersonates an account that has an ETH and AAVE balance on Kovan.

Advertisement