// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract GameItem is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("GameItem", "ITM") {}
function awardItem(address player, string memory tokenURI)
public
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
I have an ERC721 contract and have awarded some tokens to an address. Just playing around in truffle querying the contract.. but having a problem wit balanceOf..
truffle(development)> x = instance.balanceOf('0x295A360036B71cd1223e11EDEC2903913BfC6a63')
BN { negative: 0, words: [ 4, <1 empty item> ], length: 1, red: null }
truffle(development)> x.words[0]
evalmachine.<anonymous>:0
x.words[0]
^
Uncaught TypeError: Cannot read property '0' of undefined
at evalmachine.<anonymous>:0:8
at sigintHandlersWrap (vm.js:273:12)
at Script.runInContext (vm.js:142:14)
at runScript (/Users/xxx/.nvm/versions/node/v14.17.4/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:364:1)
at Console.interpret (/Users/xxx/.nvm/versions/node/v14.17.4/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:379:1)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:821:10)
at REPLServer.emit (events.js:400:28)
at REPLServer.emit (domain.js:470:12)
how can I read the 'words' ?
.toString()to get a readable number. – Jesse Clark Oct 11 '21 at 14:24