js
js copied to clipboard
error only in findAllByOwner 'Assertion failed'
Hi I'm using version 0.11.6 and findAllByOwner doesn't seem to be working.
const { publicKey: walletId } = useWallet()
const myNfts = await metaplex.nfts().findAllByOwner(walletId)
I also tried this implementation, same error.
import { walletAdapterIdentity } from "@metaplex-foundation/js";
import { useWallet } from '@solana/wallet-adapter-react';
const { wallet } = useWallet();
if (wallet) {
metaplex.use(walletAdapterIdentity(wallet));
const myNfts = await metaplex.nfts().findAllByOwner(metaplex.identity().publicKey);
}
Getting the same issue. Seems to be something in bn.js, right? Possibly a dupe of #150 but I saw no resolution there either. Here's my stack trace:
Error: Assertion failed
at assert (/Users/username/work/msg/node_modules/bn.js/lib/bn.js:6:21)
at BN._initArray (/Users/username/work/msg/node_modules/bn.js/lib/bn.js:145:5)
at BN.init [as _init] (/Users/username/work/msg/node_modules/bn.js/lib/bn.js:86:19)
at new BN (/Users/username/work/msg/node_modules/bn.js/lib/bn.js:39:12)
at TokenGpaBuilder.where (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/utils/GpaBuilder.ts:71:29)
at TokenGpaBuilder.whereOwner (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/programs/token/gpaBuilders/TokenGpaBuilder.ts:26:17)
at Object.handle (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/plugins/nftModule/findNftsByOwner.ts:23:10)
at Task.callback (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/plugins/operationModule/OperationClient.ts:66:31)
at callback (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/utils/Task.ts:82:50)
at Disposable.run (/Users/username/work/msg/node_modules/@metaplex-foundation/js/src/utils/Disposable.ts:34:36)
ran into this over the weekend too and had a fun debugging session. the issue stems from this instanceof call here: https://github.com/metaplex-foundation/js/blob/e8205e7c2dbda1258402602adac94f85804c9be3/src/utils/GpaBuilder.ts#L65-L68 (in most cases, likely the first one trying to check instanceof PublicKey).
depending on your node_modules layout and how things get packaged, the imported PublicKey from @metaplex-foundation/js is different than the imported PublicKey from the application callsite, which causes this instanceof check to fail and goes to the last branch in this control flow which leads to the assertion error listed above. i patched this by changing that instanceof check to check the constructor name (super hacky), but i think the real solution is that this package should likely not have a hard dependency on @solana/web3.js but rather a peerDependency to allow proper hoisting by npm / yarn.
my colleague @steveluscher has a more useful breakdown of a similar issue here
Possibly a dupe of #150
(this is a dupe of #150 but i think this thread has more / better info)
Hey 👋 I've worked on a big refactor of the SDK lately that I will publish as soon as I've got some time to document the changes. I'm hoping that this refactoring could fix this issue since it relies more on types than classes but can't guarantee this. Bear with me on that one. If it doesn't fix it, I'll investigate deeper.
Worked for me when I used the wallet as a String, instead of a PublicKey or BN Object!
Worked for me when I used the wallet as a String, instead of a PublicKey or BN Object!
@KobeBlockify nice this is actually working, although type PublicKey has been set to owner argument for findAllByOwner method

@lorisleiva Just tagging you here just incase this helps.
Hey all 👋
I've published a new version v0.12.1 that aims to fix this issue.
Could you please upgrade and let me know if it works for you?
Still doesn't work @lorisleiva, the metaplex object returned has no functions available. Tried v0.12.1 and v0.12.2.
Hi there 👋
I'm going to close this due to inactivity but feel free to open a new issue using the latest version with updated information if you need to.
Thank you for your understanding.