我有一个看起来像这样的合同:
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
是我的合同对象。我想对React组件中的manager变量进行简单的调用,例如:
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扩展错误,这是绝对无法理解的:
任何帮助表示赞赏!
答案 0 :(得分:0)
您使用的是哪个Web3版本?显然,它在beta.41
中不起作用。考虑安装beta.37
。
npm install --save web3@1.0.0-beta.37
参考:https://github.com/MetaMask/metamask-extension/issues/6080