我有一份看起来像这样的合同:
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
是我的合同对象。我想对反应组件中的 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 扩展错误:
任何帮助表示赞赏!