gpt4 book ai didi

compiler-errors - SOLIDITY REMIX 编译器,在部署我的合约后出现此错误(无效的 BigNumber 字符串)

转载 作者:行者123 更新时间:2023-12-05 06:01:03 25 4
gpt4 key购买 nike

我正在研究我的 Udemy 类(class)项目..这门类(class)的问题是使用了旧版本 solidity 0.4.17..我正在尝试将此项目更新为当前版本...更新代码后并尝试在 Remix 编译器上编译...它编译时在特定行上没有任何错误或警告,但是当我尝试在 remix 上部署合约时:

它显示:

创建事件出错:参数编码错误:错误:BigNumber 字符串无效(argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.1.1)

所以我不太明白这里的问题是什么?

这是我的 solidity 合约代码:

    // SPDX-License-Identifier: GPL-3.0

pragma solidity >0.4.17 <0.8.0;

contract CampaignFactory {

address[] public deployedCampaigns;

function createCampaign(uint minimum) public {
address newCampaign = address ( new Campaign(minimum, msg.sender));
deployedCampaigns.push(newCampaign);
}

function getDeployedCampaigns() public view returns (address[] memory) {
return deployedCampaigns;
}
}

contract Campaign {

struct Request {
string description;
uint value;
address recipient;
bool complete;
uint approvalCount;
mapping(address => bool) approvals;
}

Request[] public requests;
address public manager;

uint public minimumContribution;

mapping(address => bool) public approvers;

uint public approversCount;

modifier restricted() {
require(msg.sender == manager);
_;
}

constructor(uint minimum, address creator){

manager = creator;
minimumContribution = minimum;
}

function contribute() public payable {
require(msg.value > minimumContribution);

approvers[msg.sender] = true;
approversCount++;
}

uint numRequest;


function creatRequest(string memory description, uint value, address recipient) public restricted {

Request storage newRequest = requests[numRequest++];
newRequest.description = description;
newRequest.value = value;
newRequest.recipient = recipient;
newRequest.complete = false;
newRequest.approvalCount = 0;

}

function approveRequest(uint index) public {
Request storage request = requests[index];
require(approvers[msg.sender]);
require(!request.approvals[msg.sender]);

request.approvals[msg.sender] = true;
request.approvalCount++;
}


function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];

require(request.approvalCount > (approversCount / 2));
require(!request.complete);

payable(request.recipient).transfer(request.value);
request.complete = true;
}
}

预先感谢您花时间看这个问题...

编辑:

好的,我管理器传递了这个错误,但是现在当我尝试创建我的请求时,我得到了一个错误:

[vm] from: 0x5B3...eddC4to: Campaign.creatRequest(string,uint256,address) 0x7b9...b6AcEvalue: 0 weidata: 0x83e...00000logs: 0hash: 0x8d9...a5ccb交易到 Campaign.creatRequest 错误:VM 错误:无效的操作码。 invalid opcode 执行可能已抛出。调试事务以获取更多信息。

所以我做的步骤:

  1. 将我的最低贡献设置为“0”并添加创作者地址“0x0ABC”

  2. 我用相同的地址“0x0ABC”贡献了 1 个以太币

  3. 然后我从混音副本中随机选择一个不同的地址并粘贴到我的“创建请求”我添加字符串“字符串”金额“单位”地址“0x0CCC”

当我点击 createRequest 时,我得到了上面提到的这个错误;

enter image description here

enter image description here

最佳答案

Solidity 目前 (v0.8) 不允许将“包含映射的结构”写入存储数组。但是您可以将其写入映射

mapping (uint => Request) public requests;  // changed to mapping

代替

Request[] public requests;  // original code

您将失去检索数组长度的能力。但是您已经将它保存在 numRequest 变量中,所以一切都很好。

关于compiler-errors - SOLIDITY REMIX 编译器,在部署我的合约后出现此错误(无效的 BigNumber 字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67349342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com