Hey everyone! I’m new to NEAR and NFTs. I’ve been following this cool zero to hero NFT guide that uses CLI commands. It works fine when I use the command line, but I’m having a hard time turning it into JavaScript code.
I’ve got the contract loaded up like this:
myNFTContract = await nearConnection.loadContract(contractAddress, {
viewMethods: ['getNFTInfo', 'checkOwnership', 'totalSupply'],
changeMethods: ['createNFT', 'transferNFT', 'burnNFT'],
sender: currentUser.accountId
});
Now I’m trying to call a simple view function, like this:
let result = await myNFTContract.getNFTInfo()
But I keep getting this error about a missing account_id field. I’m confused because the CLI version clearly uses an account ID argument, but the JavaScript examples I’ve seen don’t mention it.
Am I missing something in how I’m setting up the contract or logging in? Any help would be awesome!
hey creativePainter45! sounds like ur having a tricky time with the js implementation. for view functions, u might need to pass the account_id as an argument even in js. try something like:
let result = await myNFTContract.getNFTInfo({ account_id: currentUser.accountId })
let me know if that helps!
It seems you’ve encountered a common issue when transitioning from CLI to JavaScript with NEAR NFTs. The discrepancy you’re experiencing is due to the way arguments are handled in different contexts.
For view functions in JavaScript, you typically need to pass arguments as an object, even if it’s not immediately apparent from CLI examples. Try modifying your function call like this:
let result = await myNFTContract.getNFTInfo({ account_id: currentUser.accountId });
This should resolve the missing ‘account_id’ field error. If you’re still facing issues, double-check that ‘currentUser.accountId’ is correctly set and that you’re properly authenticated with the NEAR network before making the call.
Remember, always refer to the contract’s specific implementation as function signatures may vary between different NFT contracts.
hey there creativePainter45! i totally get your frustration with the whole CLI to JavaScript thing. it can be a real head-scratcher sometimes, right?
have you tried passing the account_id as an object in your function call? something like this might work:
let result = await myNFTContract.getNFTInfo({ account_id: currentUser.accountId })
also, just curious - what kind of NFTs are you working on? sounds like an exciting project! 
oh, and one more thing - make sure you’re actually connected to the network before making any calls. i’ve definitely forgotten that step before and spent way too long wondering why nothing was working 
let us know how it goes! and if you hit any more snags, don’t hesitate to ask. we’re all learning here!