【问题标题】:Metamask chrome extension gives error. How do I fix this?Metamask chrome 扩展给出错误。我该如何解决?
【发布时间】: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


【解决方案1】:

你发现了吗?你可以直接调用 this.setState({ allcandidates: result })

此外,setVote 的结果不是任何内容,因为您没有让它返回 solc 合约中的任何内容。

【讨论】:

  • 你是在问还是在回答?我有点没明白你的意思。对不起。另外,是的,setVote() 没有返回任何东西,因为我故意不希望返回任何东西。对于访问投票,我使用 getter 方法 getVote()
  • 已经 2 周大了,所以我在问。我无法发表评论,所以我不得不写一个答案。
  • 我猜你没有问题了?
  • 哦!好的,对不起。是的,我不再有这个问题了。我想知道我做了什么。但我有点记得改变了我的solidity代码。问题出在无法完成完整交易的地方。由于没有完整的事务,VM 恢复了它的进程并给出了上述错误。我希望这有帮助。在完全确定问题后,我会发布答案。
猜你喜欢
  • 1970-01-01
  • 2019-06-28
  • 2022-07-12
  • 2018-09-20
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 2021-11-15
  • 2020-02-14
相关资源
最近更新 更多