I am working on a project using ERC721. Code below

pragma solidity >=0.4.21 <0.7.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract Sketch is ERC721 {
  string[] public sketchs;
  mapping(string => bool) _sketchExists;
  constructor() ERC721("Sketch", "SKETCH") public {
  function mint(string memory _sketch) public {
    uint _id = sketchs.push(_sketch);
    _mint(msg.sender, _id);
    _sketchExists[_sketch] = true;

But when I truffle migrate I get a TypeError "Different number of components on the left hand side (1) than on the right hand side (0)". Because uint _id has 1 and sketchs has 0

uint _id = sketchs.push(_sketch);

Is that because my sketchs array starts at 0? If that is the case how would I initialize this then? Any direction/assistance would be great, thanks in advance!

1 Answer 1


Operation push has changed behavior since since solidity 0.6. It no longer returns the length but a reference to the added element.

You can solve this by splitting the assignment in two operations:

uint _id = sketchs.length - 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.