Я успешно скомпилировал и развернул мой умный контракт Campaign.sol
.Все функции в моем контракте могут работать успешно, но, поскольку я использую свой javascript-файл RequestRow.js
для вызова своей функции finalizeRequest
Метамаска выскакивает ошибка Transaction error. Exception thrown in contract code
Я погуглил эту ошибку и попытался решить мой вопрос это и это .Тем не менее, они не полезны для моей ошибки.Может кто-нибудь подскажет, где я ошибся в своем умном контракте.Я не знаю, как это решить.Пожалуйста, помогите!
Мой Campaign.sol
файл
pragma solidity ^0.4.17;
contract CampaignFactory{
address[] public deployedCampaigns;
function createCampaign(uint minimum)public{
address newCampaign = new Campaign(minimum, msg.sender);
deployedCampaigns.push(newCampaign);
}
function getDeployedCampaign() public view returns(address[]){
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);
_;
}
function Campaign (uint minimum, address creator)public{
manager = creator;
minimumContribution = minimum;
}
function contribue()public payable{
require(msg.value > minimumContribution);
approvers[msg.sender] = true;
approversCount++;
}
function createRequest(string description, uint value, address recipient)public restricted{
Request memory newRequest = Request({
description: description,
value: value,
recipient: recipient,
complete: false,
approvalCount: 0
});
requests.push(newRequest);
}
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);
request.recipient.transfer(request.value);
request.complete = true;
}
function getSummary() public view returns (
uint, uint, uint, uint, address
){
return (
minimumContribution,
this.balance,
requests.length,
approversCount,
manager
);
}
function getRequestsCount() public view returns (uint){
return requests.length;
}
}
Мой RequestRow.js
файл
import React, {Component} from 'react';
import {Table, Button} from 'semantic-ui-react';
import web3 from '../ethereum/web3';
import Campaign from '../ethereum/campaign';
class RequestRow extends Component{
onApprove = async() => {
const campaign = Campaign(this.props.address);
const accounts = await web3.eth.getAccounts();
await campaign.methods.approveRequest(this.props.id).send({
from: accounts[0]
});
};
onFinalize = async() => {
const campaign = Campaign(this.props.address);
const accounts = await web3.eth.getAccounts();
await campaign.methods.finalizeRequest(this.props.id).send({
from: accounts[0]
});
};
render(){
const {Row, Cell} = Table;
const {id, request, approversCount} = this.props;
return (
<Row>
<Cell>{id}</Cell>
<Cell>{request.description}</Cell>
<Cell>{web3.utils.fromWei(request.value,'ether')}</Cell>
<Cell>{request.recipient}</Cell>
<Cell>{request.approvalCount}/{approversCount}</Cell>
<Cell>
<Button color="green" basic onClick={this.onApprove}>
Approve
</Button>
</Cell>
<Cell>
<Button color="teal" basic onClick={this.onFinalize}>
Finalize
</Button>
</Cell>
</Row>
)
}
}
export default RequestRow;
Полное сообщение об ошибке, которое я получил в консоли девеопера
Uncaught (in promise) Error: Transaction has been reverted by the EVM:
{
"blockHash": "0xcca9f6dac8c99c2ecc1f9314661399bda3a6096bf0f36d1c1724d84dcece42b2",
"blockNumber": 5145820,
"contractAddress": null,
"cumulativeGasUsed": 270372,
"from": "0x284aea2dca83c9c6247907554cb27120f7ce1892",
"gasUsed": 55899,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": "0x6ff70b2a9c30909431714902581539087fe25a3b",
"transactionHash": "0x24b15e5db8bb673375409327cdde0fba98844126f5909ed7681845ee3bccce84",
"transactionIndex": 2,
"events": {}
}
at index.js?959bf61:366