【发布时间】:2018-01-14 10:40:27
【问题描述】:
我从metamask 收到此错误。
几个小时前它运行良好。我尝试重新安装/禁用并再次重新启用,但没有任何效果。
另外,
我的智能合约功能齐全(在 Remix Browser based IDE 中测试)并且没有其他错误或日志出现在任何地方。我还重新启动了 Ganache 并重新编译并重新迁移了我的合约,但没有成功。
这是我的可靠代码:
pragma solidity ^0.4.18;
contract Voting {
address mainAddress;
bytes32[] candidateNames;
mapping(bytes32 => uint) candidateVotes;
mapping(bytes32 => bytes32) candidatesDetails;
function Voting() public {
mainAddress = msg.sender;
}
modifier isMainAddress {
if (msg.sender == mainAddress) {
_;
}
}
function getAllCandidates() public view returns (bytes32[]) {
return candidateNames;
}
function setCandidate(bytes32 newCandidate) isMainAddress public {
candidateNames.push(newCandidate);
}
function setVote(bytes32 candidate) public {
candidateVotes[candidate] = candidateVotes[candidate] + 1;
}
function getVote(bytes32 candidate) public view returns (uint) {
return candidateVotes[candidate];
}
function setDescrption(bytes32 candidateName, bytes32 candidatesDesc) isMainAddress public {
candidatesDetails[candidateName] = candidatesDesc;
}
function getDescription(bytes32 candidateName) public view returns (bytes32){
return candidatesDetails[candidateName];
}
}
我将这些函数称为:
let votingContractInstance;
const contract = require('truffle-contract')
const votingContract = contract(VotingContract)
votingContract.setProvider(this.state.web3.currentProvider)
this.state.web3.eth.getAccounts((error, accounts) => {
votingContract.deployed().then((instance) => {
votingContractInstance = instance
return votingContractInstance.setVote(this.state.candidateName);
}).then((result) => {
this.setState(() => ({
allCandidates: result
}));
})
})
所有的调用都只能通过这种方式进行。
我正在使用其中一个松露盒 (
REACT box),控制台中也没有日志/错误。
【问题讨论】:
-
revert来自您调用的智能合约。如果没有看到智能合约代码和您正在拨打的电话的详细信息,就无法进一步调试。 -
请看一次 :) @smarx
-
这是我要求的一半。 :-)
-
分享其余部分的最简单方法是简单地分享您进行调用/交易的 JavaScript 代码。
-
我已经更新了这个问题。所以,很抱歉给您带来不便。这够了吗? @smarx
标签: truffle web3js web3 metamask