【问题标题】:currently i'm building a simple lottery contract with help of react but getting error .default.methods.manager is not a function in react目前我正在借助 react 构建一个简单的彩票合约,但出现错误 .default.methods.manager is not a function in react
【发布时间】:2020-06-17 15:26:37
【问题描述】:

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

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;

lottery.js

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);

【问题讨论】:

  • 需要模块'./lottery'的代码来理解这里的问题
  • @StephenS sure !

标签: reactjs solidity web3


【解决方案1】:

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

ABI 数组中仅有的函数是 setMessagemessage

【讨论】:

    猜你喜欢
    • 2020-10-12
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多