trufflesuite / drizzle

Reactive Ethereum dapp UI suite
906 stars 236 forks source link

Initial contract #60

Closed tung-eh closed 4 years ago

tung-eh commented 4 years ago

According to the drizzle docs, I can initial contract with object like

  {
    contractName: 'RegisteredContract',
    web3Contract: new web3.eth.Contract(abi, address, {data: 'deployedBytecode' }) // An instance of a Web3 contract
  }

How can I get the web3 instance to do it. As I know, I can get the web3 instance from dizzleContext but this object need to be create to pass to DrizzleContext.Provider - when drizzleContext is not available.

I'm new to Ethereum and drizzle, sorry if I misunderstood anything.

adrianmcli commented 4 years ago

If you want to initialize a contract in that method, you would have to instantiate your own Web3.js object (because as you say, there is no web3 instance at the time of initialization). This is why it's recommended to use the mainstream approach of just passing in the Truffle artifact.

Alternatively, you can do this asynchronously (i.e. waiting until the drizzleContext is available) so you don't need to create your own web3 instance.

tung-eh commented 4 years ago

Yeah, I followed the second way - asynchronously init the contract after component mounted. Thank you.