Skip to content

Lesson 7: A confusion about struct in Solidity #178

Answered by pyromaus
TreapGoGo asked this question in Q&A
Discussion options

You must be logged in to vote

solidity automatically makes little getter functions for the variables you store so you can access them externally.

address ethUsdPriceFeed = helperConfig.activeNetworkConfig().priceFeed;

trying to access the 'priceFeed' part of your NetworkConfig type variable doesn't work above cos the getter function for this has a simple end goal: to return the entire struct. It doesn't let you choose what to access before doing that.
If you change HelperConfig.sol by adding a second element to the config like so..

struct NetworkConfig {
        address priceFeed; // ETHUSD price feed
        uint chainId; // chain ID
    }
.....
NetworkConfig memory anvilConfig = NetworkConfig(address(mockPriceFeed), b…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@TreapGoGo
Comment options

Comment options

You must be logged in to vote
3 replies
@TreapGoGo
Comment options

@PatrickAlphaC
Comment options

@wilson0922
Comment options

Answer selected by TreapGoGo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants