Truffle Drizzle – How to Access web3Instance in React DApps

dappsdrizzlereacttruffleweb3js

I'm working on a dapp with the boilerplate created by running truffle unbox drizzle and need to call functions provided by the web3 instance.

Is there a way to access the web3 instance object? All we get from drizzle's store is the state.web3.status string.


Failed Attempt

There is /src/util/web3/web3Reducer.js and /src/util/web3/getWeb3.js but they both appear not to be in use. I tried adding web3Reducer to combineReducers but always get null for the web3Instance.

import { combineReducers } from 'redux'
import { routerReducer } from 'react-router-redux'
import { drizzleReducers } from 'drizzle'
import web3Reducer from './util/web3/web3Reducer'

const reducer = combineReducers({
  routing: routerReducer,
  web3Instance: web3Reducer,
  ...drizzleReducers,
})

export default reducer

Best Answer

web3 instance can be accessed via context in components. for more information please check https://github.com/trufflesuite/drizzle-react/issues/22

Related Topic