在 mint 函数中为智能合约创建现有对象的映射
Create map of existing objects in mint function for a smart contract
我对 solidity 真的很陌生,还有很多我没有完全理解。我创建了这个智能合约。我在执行测试时遇到错误,指出由于以下原因无法执行推送设置的 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 变量的索引。尽管如此,还是出现了这个错误,我不确定是版本问题还是其他问题。我目前正在使用 truffle 进行版本测试:“^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()
returns 对新添加元素的引用,而不是索引。
例子:
arts.push() = "whatever you want";
使用长度属性获取索引或新元素。
我对 solidity 真的很陌生,还有很多我没有完全理解。我创建了这个智能合约。我在执行测试时遇到错误,指出由于以下原因无法执行推送设置的 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 变量的索引。尽管如此,还是出现了这个错误,我不确定是版本问题还是其他问题。我目前正在使用 truffle 进行版本测试:“^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()
returns 对新添加元素的引用,而不是索引。 例子:
arts.push() = "whatever you want";
使用长度属性获取索引或新元素。