Skip to content

Getter function #448

Answered by alymurtazamemon
ghost asked this question in Q&A
Jun 19, 2022 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

@Alex200027fr

A getter is a function that returns a value. For all public variables, solidity creates this getter function internally so you can call that variable and get its current value.

We can also create the getter function for private and internal variables but we need to define ourselves. Like this

function functionName () public view returns(<return-type-here>) {
    return //anything you can return here.
}

Replies: 2 comments 2 replies

Comment options

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

Comment options

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

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