调用合同法导致Metamask浏览器扩展程序错误(DOM除外)

问题描述 投票:0回答:1

我有一个合同,看起来是这样的:

contract Lottery {
// public we will write a front end application that will easily access public
address public manager;
address payable[] public players;

constructor() public {
    // msg global variable when we send a tx or when we do a function call
    manager = msg.sender;
}

function enter() public payable {
    // used for validation, evaluates to true continue, evaluates to false means return immediatelty
    require(msg.value > .01 ether);
    players.push(msg.sender);
}

我在Rinkeby成功部署这一点,我使用的是metamask WEB3提供商。 lottery是我的合同对象。我想作一个简单的呼吁在一个反应​​成分这样的经理变量:

class App extends Component {

  constructor(props) {
    super(props);
    this.state = { manager: '' };
  }

  async componentDidMount() {
    // with metamask there is a default address (the first one on the array) so no need to call with from address
    try {
      const manager = await lottery.methods.manager().call();

      this.setState({ manager });
    }
    catch (err) {
      console.log(err);
    }

然而,我最终得到一个错误与Metamask扩展是绝对不可判读:

enter image description here

任何帮助表示赞赏!

web3 metamask
1个回答
0
投票

这WEB3版本您使用的?显然,它不beta.41工作。考虑安装beta.37

    npm install --save [email protected]

参考:https://github.com/MetaMask/metamask-extension/issues/6080

© www.soinside.com 2019 - 2024. All rights reserved.