我有一个合同,看起来是这样的:
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扩展是绝对不可判读:
任何帮助表示赞赏!
这WEB3版本您使用的?显然,它不beta.41
工作。考虑安装beta.37
。
npm install --save [email protected]
参考:https://github.com/MetaMask/metamask-extension/issues/6080