我已经看到了web3.eth.Contract-> getPastEvents部分 但不明白为什么会出现此错误
https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html?highlight=estimateGas#getpastevents
如果您知道此问题,请帮助我让我知道... 哦,我很抱歉 现在加上我的代码 请看这个代码 第一个=> interacts.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