chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.51k stars 843 forks source link

Can't find documentation on how to use ERC721AQueryable #414

Closed Martin-Fritsche closed 2 years ago

Martin-Fritsche commented 2 years ago

I'm trying to implement a smart contract using ERC721A. I ran into an error when I tried to implement a walletOf function that used the tokenOfOwnerByIndex(owner, number) method from ERC721Enumerable. From a previous issue, I was directed to use ERC721AQueryable's tokensOfOwner instead. However, I'm still getting errors:

:

DeclarationError: Identifier already declared. --> erc721a/contracts/IERC721A.sol:86:5: 86 struct TokenOwnership { ^ (Relevant source part starts here and spans across multiple lines). Note: The previous declaration is here: --> erc721a/contracts/ERC721A.sol:43:5:
43 struct TokenOwnership {
^ (Relevant source part starts here and spans across multiple lines).

DeclarationError: Undeclared identifier. --> erc721a/contracts/extensions/ERC721AQueryable.sol:42:53: | 42 | if (tokenId < _startTokenId() || tokenId >= _nextTokenId()) { | ^^^^^^^^^

DeclarationError: Undeclared identifier. Did you mean "_ownershipOf" or "_ownerships"? --> .deps/npm/erc721a/contracts/extensions/ERC721AQueryable.sol:45:21: | 45 | ownership = _ownershipAt(tokenId); | ^^^^^^^^^^^^

DeclarationError: Undeclared identifier. --> .deps/npm/erc721a/contracts/extensions/ERC721AQueryable.sol:93:33: | 93 | uint256 stopLimit = _nextTokenId(); | ^^^^^^

DeclarationError: Undeclared identifier. Did you mean "_ownershipOf" or "_ownerships"? --> .deps/npm/erc721a/contracts/extensions/ERC721AQueryable.sol:127:29: | 127 | ownership = _ownershipAt(i); | ^^^^^^^^^^^^

DeclarationError: Undeclared identifier. Did you mean "_ownershipOf" or "_ownerships"? --> .deps/npm/erc721a/contracts/extensions/ERC721AQueryable.sol:164:29: | 164 | ownership = _ownershipAt(i); | ^^^^^^^^^^^

THIS IS MY SMART CONTRACT CODE // SPDX-License-Identifier: MIT pragma solidity ^0.8.7;

import "erc721a/contracts/ERC721A.sol"; -- I have tried commenting this out import "erc721a/contracts/extensions/ERC721AQueryable.sol";

contract MyContract is ERC721A{

constructor() ERC721A("My Contract", "MC"){}

function walletOf() external pure returns(uint256[] memory){
    return tokensOfOwner(msg.sender);
}

}

How do I resolve this? What I'm I doing wrong?

Vectorized commented 2 years ago

Screen Shot 2022-08-25 at 1 55 07 AM

Delete the erc721a from your Remix's .deps, and let it auto re-download the latest version by simply recompiling.

Martin-Fritsche commented 2 years ago

I deleted the erc721a directory in the .dep/npm dir and still got an error.

DeclarationError: Undeclared identifier. --> contract-99c206fea4.sol:11:16: 11 return tokensOfOwner(msg.sender);

THIS IS THE FULL SMART CONTRACT THAT I'M TESTING WITH

// SPDX-License-Identifier: MIT pragma solidity ^0.8.4;

import "erc721a/contracts/ERC721A.sol"; import "erc721a/contracts/extensions/ERC721AQueryable.sol";

contract MyToken is ERC721A { constructor() ERC721A("MyToken", "MTK") {}

function walletOf() external view returns(uint256[] memory){
    return tokensOfOwner(msg.sender);
}

}

Can you point me to an example?

On Wed, Aug 24, 2022, 1:56 PM Vectorized @.***> wrote:

[image: Screen Shot 2022-08-25 at 1 55 07 AM] https://user-images.githubusercontent.com/5889274/186489456-801fac3b-42bb-447c-8727-725464ec6b54.png

Delete the erc721a from your Remix's .dep, and let it auto re-download the latest version.

— Reply to this email directly, view it on GitHub https://github.com/chiru-labs/ERC721A/issues/414#issuecomment-1226053933, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATM7B5YVQMZ6WJVXM6PQUCDV2ZO53ANCNFSM57QG763A . You are receiving this because you authored the thread.Message ID: @.***>

Martin-Fritsche commented 2 years ago

I deleted the erc721a directory in the .dep/npm dir and still got an error.

DeclarationError: Undeclared identifier. --> contract-99c206fea4.sol:11:16: 11 return tokensOfOwner(msg.sender);

THIS IS THE CODE SMART CONTRACT THAT I'M TESTING WITH

// SPDX-License-Identifier: MIT pragma solidity ^0.8.4;

import "erc721a/contracts/ERC721A.sol"; import "erc721a/contracts/extensions/ERC721AQueryable.sol";

contract MyToken is ERC721A { constructor() ERC721A("MyToken", "MTK") {}

function walletOf() external view returns(uint256[] memory){
    return tokensOfOwner(msg.sender);
}

}

Can you point me to an example?

Vectorized commented 2 years ago
contract MyToken is ERC721A {

should be

contract MyToken is ERC721A, ERC721AQueryable {
Martin-Fritsche commented 2 years ago

Hi. That didn't work either. I keep getting this error message:

DeclarationError: Undeclared identifier. --> contract-99c206fea4.sol:25:16: 25 return tokensOfOwner(msg.sender);

I'm not able to call any methods from ERC721AQuaryable. I just need to show how many nfts are owned by a particular address. If there's an example project that accomplishes this use erc721a, please let me know.

On Wed, Aug 24, 2022 at 11:09 PM Vectorized @.***> wrote:

contract MyToken is ERC721A {

should be

contract MyToken is ERC721A, ERC721AQueryable {

— Reply to this email directly, view it on GitHub https://github.com/chiru-labs/ERC721A/issues/414#issuecomment-1226717583, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATM7B5ZTQEPRF55QS4EHVJ3V23PVHANCNFSM57QG763A . You are receiving this because you authored the thread.Message ID: @.***>

Vectorized commented 2 years ago

Use this.tokensOfOwner.

Martin-Fritsche commented 2 years ago

Thanks! It worked. I feel so silly. I really appreciate your time in helping me with this.

On Thu, Aug 25, 2022 at 9:21 AM Vectorized @.***> wrote:

Use this.tokensOfOwner.

— Reply to this email directly, view it on GitHub https://github.com/chiru-labs/ERC721A/issues/414#issuecomment-1227252056, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATM7B57H6L4PA3VITD3VYG3V25XPDANCNFSM57QG763A . You are receiving this because you authored the thread.Message ID: @.***>

cygaar commented 2 years ago

Closing now as this seems resolved