question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a getter for an array of tokens held by an owner

See original GitHub issue

Problem

I want to inherit ERC721Full.sol contract and add an extra getter for an array of tokens held by a given user.

Expected behaviour

In previous versions it was possible by adding an extra function and accessing an internal _ownedTokens mapping:

function tokensOfOwner(address _owner) external view returns (uint256[]) {
    return ownedTokens[_owner];
}

Current behaviour

In version 2.x it is impossible to access a private _ownedTokens mapping.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Aniket-Enggcommented, Nov 27, 2018

shouldn’t uint256[] storage be uint256[] memory? @frangio Clear it, i will take this one.

0reactions
arzusacommented, Jul 15, 2022

I think we could add an internal function in ERC721Enumerable for this.

function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
    return _ownedTokens[owner];
}

not work

TypeError: Return argument type mapping(uint256 => uint256) is not implicitly convertible to expected type (type of first return variable) uint256[] storage pointer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I write setters and getters for an array? (c++)
Im writing a class within c++, however I am not certain on how to create the setters and getters for the arrays (sorry...
Read more >
How to write a getter function for an array of structs? "storage ...
Your issue is that you're retrieving inside userMatchesLookUp() function an uint256 array and you're returning entire array of struct.
Read more >
Payment - OpenZeppelin Docs
Getter for the total shares held by payees. totalReleased() → uint256 public. Getter for the total amount of Ether already released.
Read more >
Groovy Language Documentation
Groovy closures vs lambda expressions; Owner, delegate and this ... The first option 1 is interesting when the character is held in a...
Read more >
Curve StableSwap Exchange: Deposit Contracts
Getter for the array of underlying coins within the associated pool. ... any LP tokens of the associated pool held by this contract...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found