简体   繁体   English

构造函数错误,setter 不工作(Solidity)

[英]Constructor error, setter not working(Solidity)

I was working on my smart contract project and when I put some values at the depolyment of the contract as inputs and I got an error of saying.我正在从事我的智能合约项目,当我将一些价值作为输入的合约部署时,我说错了。

"revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information." "revert 交易已经恢复到最初的state。注意:调用的function应该是payable if you send value并且你发送的值应该小于你当前的余额。调试交易以获取更多信息。"

And my code is我的代码是

uint[] private Info;

function SetInfo(uint[] memory data) private onlyOwner{
Info = new uint[](data.length);
for(uint i = 0; i < data.length;i++){
  Info[i] = data[i];
}


constructor(uint[] memory _Info,uint[] memory _SecondInfo)
ERC721(_name, _symbol) {
SetInfo(_Info);
SetSecondInfo(_SecondInfo)
}

I tried to adjust your smart contract.我试图调整你的智能合约。 I put some comments that will help you to understand what I did and your errors in original smart contract.我提出了一些评论,可以帮助您了解我所做的以及您在原始智能合约中的错误。 Smart contract code:智能合约代码:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

// Your class must  inheritance ERC721 smart contract, if you want to use its functions
contract Test is ERC721 {
    uint[] private Info;
    // Specify variable that will contain  owner address when contract will create.
    address owner;

    modifier onlyOwner() {
        require(msg.sender == owner, "You aren't the owner!");
        _;
    }

    // You must to give a name and symbol about your ERC721 token
    constructor(uint[] memory _Info, uint[] memory _SecondInfo) ERC721("TESTToken", "TST") {
        // Set owner variable with msg.sender value 
        owner = msg.sender;
        SetInfo(_Info);
        SetSecondInfo(_SecondInfo);
    } 

    function SetInfo(uint[] memory data) private onlyOwner {
        Info = new uint[](data.length);
        for(uint i = 0; i < data.length;i++){
            Info[i] = data[i];
        }
    }

    function SetSecondInfo(uint[] memory data) private onlyOwner {
        // your logic
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM