makerdao / multicall.js

Multicall.js: A JavaScript blockchain state management library for dapps
MIT License
421 stars 97 forks source link

How to get data only once ? #39

Open lolosj opened 3 years ago

lolosj commented 3 years ago

Hey, amazing piece of code. But something I don't understand : what is the proper way to use it if I don't need to "subscribe" to any update ? I just need the data once. Thank's !

terryyyyyy commented 3 years ago

Hey, amazing piece of code. But something I don't understand : what is the proper way to use it if I don't need to "subscribe" to any update ? I just need the data once. Thank's !

I also want to ask this question, does it support such a function at present

fryheid commented 3 years ago

Hey, amazing piece of code. But something I don't understand : what is the proper way to use it if I don't need to "subscribe" to any update ? I just need the data once. Thank's !

I also want to ask this question, does it support such a function at present

Yes. You can import the aggregate function instead of the createWatcher. The watcher uses the aggregate function internally. I import it with a require const { aggregate } = require('@makerdao/multicall') and then call it like you would the createWatcher but with an await since it's async await aggregate(calls, config)