问题描述
我真的很坚强,仍然有很多我没有完全了解。我已经创建了这个智能合约。我在进行测试时收到错误消息,说明由于以下原因,无法执行由推送设置的ID:
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
^------------------------^
我了解到,推送仅接收一个属性,并且应该能够稳定索引id变量。尽管如此,仍会发生此错误,我不确定它是版本还是其他名称。我目前正在将松露用于版本为“ ^ 0.6.0”的测试。我将衷心感谢您的帮助。预先感谢!
这是我的代码:
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
解决方法
push()
返回对新添加元素的引用,而不是索引。 例子:
arts.push()=“任何您想要的”;
使用length属性获取索引或新元素。