truffle-box / drizzle-box

This box comes with everything you need to start using smart contracts from a react app with Drizzle. It includes drizzle, drizzle-react and drizzle-react-components to give you a complete overview of Drizzle's capabilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get the web3 instance?

vertangelx opened this issue · comments

I need to perform something using the web3 instance, like

this.props.web3.eth.getBalance(address)

Drizzle only provides us with state.web3.status, not the web3 instance itself. However there are some unused files that might be able to help us achieve this in source/util/web3.

Any ideas on how we can expose/access the actual web3 instance?

Should be this.context.drizzle.web3.eth.getBalance(address) - need to make sure that you are passing 'context' variable in constructor - should look like this:

class ComponentName extends Component {
constructor(props, context) {
    super(props)

    /* local state variables */
    this.state = {
      tokenName: '',
      tokenBalance: 0,
    }

    this.handleClose = this.handleClose.bind(this);
    this.handleCloseAgain = this.handleCloseAgain.bind(this);
  }
  ...

}

ComponentName.contextTypes = {
  drizzle: PropTypes.object
}
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

commented

This issue has been closed, but can be re-opened if further comments indicate that the problem persists. Feel free to tag maintainers if there is no reply to further comments.