truffle-box / drizzle-react-native-box

This box is to help get you started with building dapps with Drizzle on React Native.
18 stars 8 forks source link

Read contract with infura provider #2

Open Vulturio opened 5 years ago

Vulturio commented 5 years ago

Is there a way to read an existing contract data with an Infura provider? Any example? In truffle-react exist an "getWeb3.js" file with that options, in drizzle-react-native I can change that. Any solution?

honestbonsai commented 5 years ago

@UncleVultur Take a look at the README for Drizzle options. You should be able to pass in your own fallback web3 provider which you can point to Infura. Haven't tried it out myself, but that's where I'd start.

Relevant Drizzle code https://github.com/trufflesuite/drizzle/blob/f2110938434d869d2f379197c758ba84d1d66383/src/web3/web3Saga.js#L43

Let me know how it goes. If it works, please close the issue. Thanks!

aklevecz commented 5 years ago

@honestbonsai I'm able to initialize the infura provider by passing it into the fallback option, and building drizzle with a web3 version that is not 1.0.0.35-beta, but whenever drizzle polls for new blocks I get this error:

Error in block processing: @ index.js:1446
index.js:1446 TypeError: Cannot read property 'transactions' of null
    at processBlock$ (drizzle.js:16970)
    at tryCatch (drizzle.js:13931)
    at Generator.invoke [as _invoke] (drizzle.js:14158)
    at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/drizzle/dist/drizzle.js:13984:29)
    at next (proc.js:362)
    at currCb (proc.js:449)
    at eval (proc.js:567)
    at exec (scheduler.js:20)
    at flush (scheduler.js:63)
    at asap (scheduler.js:35)
    at runPutEffect (proc.js:553)
    at runEffect (proc.js:496)
    at next (proc.js:366)
    at proc (proc.js:314)
    at resolveIterator (proc.js:521)
    at runCallEffect (proc.js:584)
    at runEffect (proc.js:496)
    at next (proc.js:366)
    at currCb (proc.js:449)

I get that it's happening somewhere in the processBlock saga, but I can't figure out what is wrong. The block header is appearing, but for whatever reason the block isn't being found using the number.

honestbonsai commented 5 years ago

@traysiMay I believe anything past web3 1.0.0.35-beta has some issues with Drizzle. See: https://github.com/trufflesuite/drizzle/releases/tag/1.3.3

Take a shot with the 1.3.3 release of Drizzle and let me know how it goes.

aklevecz commented 5 years ago

I got it to work by building drizzle with web3 1.0.0.33 and changing the blocksSaga to retry calling web3.eth.getBlock under the processBlockHeader generator. For some reason the first call returns nothing most of the time, but a slightly delayed call works.

here is my very naive approach to get it to work.

let block = yield call(web3.eth.getBlock, blockNumber, true)
let retries = 0
const maxRetries = 20
while (!block && retries < maxRetries) {
  block = yield call(web3.eth.getBlock, blockNumber, true)
  retries+=1
}
yield call(processBlock, { block, drizzle, web3, syncAlways })