0

I'm really new to solidity and there is still alot I dont fully get. I have created this smart contract. I am getting an error while performing a test stating that the id to be set by the push cant be performed due to the following:

Error: Different number of components on the left hand side (1) than on the right hand side (0).
        uint _id = arts.push(_art);//create ids
        ^------------------------^

I understand that the push receives only one atribute and should be able to stablish the index to the id variable. Nontheless this bugg occurs, I'm not sure if its the version or something else. I'm currently using truffle for the tests with version: "^0.6.0". I would really appreciate your help. Thanks in advance!

Here's my code:

pragma solidity >=0.4.21 <0.7.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract Art is ERC721{

    string[] public arts;

    mapping(string => bool) _artExists;//similar to json or hash

    constructor() ERC721("Art", "DATA") public {
    }

    //E.G color = "#FFFFFF"

    //create art restrict in the future to mentors
    function mint(string memory _art) public{
        //Require unique Art
        require(!_artExists[_art]);
        uint _id = arts.push(_art);//create ids
              //address
        
        _mint(msg.sender, _id);
        _artExists[_art] = true;

        //Art - track it & add it
        //Call the mint function
        //Art - track it 
        



    }

}
//mint function
0

The 0.6.0 solidity release introduces the following breaking change (https://solidity.readthedocs.io/en/v0.6.2/060-breaking-changes.html) :

The function push(value) for dynamic storage arrays does not return the new length anymore (it returns nothing).

So you have to change uint _id = arts.push(_art); to arts.push(_art); and then the rest of your code to match this modification. Note that you can access the length of an array using array.length.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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