Необработанный отказ (TypeError): невозможно прочитать свойство 'getPastEvents' из неопределенного - PullRequest
0 голосов
/ 11 октября 2019

Я уже вижу раздел web3.eth.Contract -> getPastEvents, но не понимаю, почему появляется эта ошибка

screenshot error message

https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html?highlight=estimateGas#getpastevents

, если вызнаю эту проблему, пожалуйста, помогите мне, дайте мне знать ... О, мне очень жаль, а теперь мой код, пожалуйста, посмотрите этот код первый => взаимодействия.js второй один => resucers.js

import Web3 from 'web3'
import {
  web3Loaded,
  web3AccountLoaded,
  tokenLoaded,
  exchangeLoaded,
  cancelledOrdersLoaded
} from './actions'
import Token from '../abis/Token.json'
import Exchange from '../abis/Exchange.json'

export const loadWeb3 = (dispatch) => {
  const web3 = new Web3(Web3.givenProvider || 'http://localhost:7545')
  dispatch(web3Loaded(web3))
  return web3
}

export const loadAccount = async (web3, dispatch) => {
  const accounts = await web3.eth.getAccounts()
  const account = accounts[0]
  dispatch(web3AccountLoaded(account))
  return account
}

export const loadToken = async (web3, networkId, dispatch) => {
    try {
        const token = new web3.eth.Contract(Token.abi, Token.networks[networkId].address)       // new 이거 의존성(버전) 문제 이거 조심!!!!!
        dispatch(tokenLoaded(token))
        return token
    } catch (error) {
        console.log('Contract not deployed to the current network. Please select another network with Metamask.')
        return null
    }
} 

export const loadExchange = async (web3, networkId, dispatch) => {
  try {
    const exchange = new web3.eth.Contract(Exchange.abi, Exchange.networks[networkId].address)      // new 이거 의존성(버전) 문제 이거 조심!!!!!
    dispatch(exchangeLoaded(exchange))
    return exchange
  } catch (error) {
    console.log('Contract not deployed to the current network. Please select another network with Metamask.')
    return null
  }
}

export const loadAllOrders = async (exchange, dispatch) => {
  // Fetch cancelled orders with the "Cancel" event stream
  const cancelStream = await exchange.getPastEvents('Cancel', { fromBlock: 0, toBlock: 'latest' })
  // // Format cancelled orders

  const cancelledOrders = cancelStream.map((event) => event.returnValues)
  // Add cancelled orders to the redux store
  dispatch(cancelledOrdersLoaded(cancelledOrders))

  // // Fetch filled orders with the "Trade" event stream
  // const tradeStream = await exchange.getPastEvents('Trade', { fromBlock: 0, toBlock: 'latest' })
  // // Format filled orders
  // const filledOrders = tradeStream.map((event) => event.returnValues)
  // // Add cancelled orders to the redux store
  // dispatch(filledOrdersLoaded(filledOrders))

  // // Load order stream
  // const orderStream = await exchange.getPastEvents('Order', { fromBlock: 0,  toBlock: 'latest' })
  // // Format order stream
  // const allOrders = orderStream.map((event) => event.returnValues)
  // // Add open orders to the redux store
  // dispatch(allOrdersLoaded(allOrders))
}

import { combineReducers } from 'redux';

function web3(state={}, action) {
    switch (action.type) {
        case 'WEB3_LOADED':
            return { ...state,  connection: action.connection }
        case 'WEB3_ACCOUNT_LOADED':
            return { ...state, account: action.account }
        default:
            return state
    }
}

function token(state = {}, action) {
  switch (action.type) {
    case 'TOKEN_LOADED':
      return { ...state, loaded: true, contract: action.contract }
    default:
      return state
  }
}

function exchange(state = {}, action) {
  switch (action.type) {
    case 'EXCHANGE_LOADED':
      return { ...state, loaded: true, contract: action.contract }
    case 'CANCELLED_ORDERS_LOADED':
      return { ...state, cancelledOrders: { loaded: true, data: action.cancelledOrders } }
    // case 'FILLED_ORDERS_LOADED':
    //   return { ...state, filledOrders: { loaded: true, data: action.filledOrders } }
    // case 'ALL_ORDERS_LOADED':
    //   return { ...state, allOrders: { loaded: true, data: action.allOrders } }
    default:
      return state
  }
}

const rootReducer = combineReducers({
  web3,
  token,
  exchange
})

export default rootReducer
...