构造函数错误,设置器不起作用(坚固)

发布于 2025-01-22 04:52:07 字数 493 浏览 0 评论 0原文

我正在从事智能合同项目,当我将提出一些价值观时,在合同的分散时作为输入,我遇到了一个说法。

“还原 交易已恢复为初始状态。 注意:如果发送值和 您发送的价值应小于当前余额。 调试交易以获取更多信息。”

我的代码是

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 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."

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)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2025-01-29 04:52:07

我试图调整您的智能合同。我提出了一些评论,可以帮助您了解我的所作所为以及原始智能合约中的错误。
智能合约代码:

// 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
    }
}

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文