0

I'm currently in the early stages of learning solidity and diving into the blockchain world; I do have prior programming experience.

I'm currently stumped on something that seems rather trivial, but is stopping my progress.

I am trying to request the price of the LINK token from AAVE V3. The code I am using is as follows:

pragma solidity ^0.8.0;

import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPriceOracleGetter.sol";
import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol";

contract Flash {

    event print_value(uint256 indexed value1);

    function getPrice() public view returns(uint256) {
        IPoolAddressesProvider provider = IPoolAddressesProvider(address(0xC87385b5E62099f92d490750Fcd6C901a524BBcA));
        address priceOracleAddress = provider.getPriceOracle();
        IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

        address daiAddress = address(0x6A639d29454287B3cBB632Aa9f93bfB89E3fd18f); 
        uint256 price = priceOracle.getAssetPrice(daiAddress);
        // emit print_value(price);
        return price;
    }

} 

And the error I am receiving is:

call to Flash.getPrice errored: Internal JSON-RPC error.
{
  "code": -32000,
  "message": "execution reverted"
}

I am using the ETH Goerli Testnet, with the contract developed with Remix and deployed via "Injected Provider - Metamask".

The addresses I am using have been collected from this doc page: https://docs.aave.com/developers/deployed-contracts/v3-testnet-addresses

And the RPC details for the testnet are: RPCUrl = https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 ChainID = 5

As with learning any new language, I believe my current hang-up is my inability to properly debug this issue further, or perhaps I'm simply on the wrong chain.

Any help will be much appreciated.

Update:

Interestingly, if I switch to the Avalanche Fuji Testnet I am able to get a response, but it is Zero - despite updating the addresses to reflect the Fuji AAVE addresses.

1 Answer 1

0

The revert happened because you used an incompatible address to the interface IPoolAddressesProvider. In goerli testnet that address should be 0xc4dCB5126a3AfEd129BC3668Ea19285A9f56D15D as stated in the document. The fix :

    function getPrice() public view returns(uint256) {
        IPoolAddressesProvider provider = IPoolAddressesProvider(address(0xc4dCB5126a3AfEd129BC3668Ea19285A9f56D15D));
        address priceOracleAddress = provider.getPriceOracle();
        IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

        // address of link token Goerli
        address daiAddress = address(0x07C725d58437504CA5f814AE406e70E21C5e8e9e); 
        uint256 price = priceOracle.getAssetPrice(daiAddress);
        // emit print_value(price);
        return price;
    }

Note that I change the daiaddress to something else (LINK-TestnetMintableERC20-Aave in the document) to see the price different than 0. Output of getPrice() : uint256: 3000000000

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.