reactjs 目前我正在react的帮助下构建一个简单的彩票合约,但是得到错误,default.methods.manager不是react中的函数

yzuktlbb  于 2023-01-04  发布在  React
关注(0)|答案(1)|浏览(120)

目前,我正在react.js的帮助下建立一个简单的彩票合同。这是我的app.js文件在react.jsweb3,彩票合同是工作良好的混音找不到这个文件中的错误。

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import web3 from './web3';
import lottery from './lottery';

class App extends Component {

constructor(props) {
super(props);

this.state = { manager: '' };
}

async componentDidMount() {
const manager = await lottery.methods.manager().call();

this.setState({ manager });
}

render(){
return (
<div>
  <h2> Lottery contract</h2>
  <p>this contract if managed by {this.state.manager}</p>
</div>
      
);
}

}

export default App;

彩票网站

import web3 from './web3';

const address = '0xBEFF762b1A78D1263b43e72630843D093B5c36d4';

const abi = [
    {"constant":false,"inputs":[{"name":"newMessage","type":"string"}],"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initialMessage","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];

export default new web3.eth.Contract(abi, address);

7cjasjjr

7cjasjjr1#

您的ABI阵列似乎没有名为manager的函数,因此可能会引发错误default.methods.manager is not a function
ABI阵列中的函数只有setMessagemessage

相关问题