Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ERC721 getters internally #1993

Closed
nventuro opened this issue Nov 13, 2019 · 8 comments
Closed

Expose ERC721 getters internally #1993

nventuro opened this issue Nov 13, 2019 · 8 comments
Labels
contracts Smart contract code.

Comments

@nventuro
Copy link
Contributor

Spawned from #1970

Currently, name, symbol, tokenURI and (soon to be added) baseURI are external. The reason for this is not open up the API unnecessarily, but in this case little harm can come from providing these methods, and having public getters would allow users (and ourselves) to implement interesting mechanisms, such as auto-generated tokenURIs.

We should change all of these getters to public.

@nventuro nventuro added the contracts Smart contract code. label Nov 13, 2019
@balajipachai
Copy link
Contributor

@nventuro
Existing:

/**
* @dev Gets the token name.
* @return string representing the token name
*/
function name() external view returns (string memory) {
        return _name;
}

Proposed change:

/**
* @dev Gets the token name.
* @return string representing the token name
*/
function name() public view returns (string memory) {
        return _name;
}

Is this the correct understanding?

Why this confusion?
PR Header: Expose ERC721 getters internally
Your comment: We should change all of these getters to public.

@frangio
Copy link
Contributor

frangio commented Nov 19, 2019

That's because they are currently already exposed externally, but they should also be available internaly. public is what achieves this combination.

@nventuro
Copy link
Contributor Author

@balajipachai correct! I meant external doesn't make the getters available internally, and we should do it (via public).

@balajipachai
Copy link
Contributor

@nventuro and @frangio
Example of calling an external function from within a contract:

pragma solidity >=0.4.22 <0.6.0;

contract Test {
    uint256 public data;
    
    constructor(uint256 _data) public {
        data = _data;
    }
    
    function getData() external view returns (uint256) {
        return data;
    }
    
    function getDataFromFunctionDefinedExternal() public view returns (uint256) {
        return this.getData();
    }
}

Can't we just use this.externalFuncName wherever required within the contract instead of making them public?

@nventuro
Copy link
Contributor Author

The this.function() syntax emits a CALL opcode, which is a much more expensive operation than an internal jump, and making the functions public doesn't create any security concerns, nor should it change the code generated when the internal getters are not used.

@balajipachai
Copy link
Contributor

@nventuro Ok cool, out of curiosity how do you guys come to know that there will be CALL, DELEGATECALL etc OPCODE is involved? Could you please suggest some links wherein I could get information about this?

And yes will start changing the functions to public from external.

Thanks.

@Godtide
Copy link

Godtide commented Nov 30, 2019

ERC721 is a library, mostly inherited by other contract. The modifier external view tells the EVM that the function reads from the Blockchain and it getters available outside the contract.

"The idea is reducing gas cost!!!!!! and making the getters available outside the contract (inheritable)" not otherwise

https://ethereum.stackexchange.com/questions/19380/external-vs-public-best-practices/55426#55426

@Amxx
Copy link
Collaborator

Amxx commented Feb 15, 2021

name,symbol,tokenURI,baseURI are public

@Amxx Amxx closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code.
Projects
None yet
Development

No branches or pull requests

5 participants