uniswap / redux-multicall Goto Github PK
View Code? Open in Web Editor NEWA React + Redux library for fetching, batching, and caching chain state via the MultiCall contract.
License: MIT License
A React + Redux library for fetching, batching, and caching chain state via the MultiCall contract.
License: MIT License
Currently, this lib's interface (Updater + hooks) were designed with the intention of using 1 active chain at a time.
For consumers using multiple active chains, this requires inelegant solutions to use multiple copies of the hooks at once.
Explore options for supporting multiple chains in an efficient way with a consumer-friendly interface.
Hey folks!
We're currently upgrading our codebase using @uniswap/widgets
to react@18
and the following line blocks installation of react 18.
Could you please update it to >=17
like it's done in @uniswap/widgets
?
Line 61 in 8b68196
Currently using this package on a layer 2 Blockchain and I'm wondering what value to set for blockPerfetch as I don't know the parameters to consider.
For context, the blockchain Is Nahmii blockchain
Hi, been experimenting using the multicall library in conjunction with the web3-react library. Ran into some difficulties with the build version, namely that in utils/callState.ts
, we have:
export function toCallState(
callResult: CallResult | undefined,
contractInterface: utils.Interface | undefined,
fragment: utils.FunctionFragment | undefined,
latestBlockNumber: number | undefined
): CallState {
if (!callResult) return INVALID_CALL_STATE
const { valid, data, blockNumber } = callResult
if (!valid) return INVALID_CALL_STATE
if (valid && !blockNumber) return LOADING_CALL_STATE
if (!contractInterface || !fragment || !latestBlockNumber) return LOADING_CALL_STATE
LOADING_CALL_STATE
in particular covers several options:
The blockNumber
is particularly challenging, as it is computed from several prior hooks and related function calls (useCallDataSubscription
> callKeysToCalls
> toCallKey
), which results in:
// result =
return { valid: true, data, blockNumber: result?.blockNumber }
So, as a user, I might suspect I'm missing the blockNumber
in the result, but it's challenging to understand exactly where the error in the contract call might be, that we can fix in order to move the call from LOADING_CALL_STATE
.
Would welcome some initial feedback on the causes of the above, then would be happy to start working on a PR.
I wrote a series of comprehensive articles for anyone strugling to use this library in their application
Part A - Explains what redux-multicall is and why you should use it: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-a-b263b14ac
Part B - A practical guide to setting up redux-multicall for use in your dApp: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-b-e92cccb0f2e6
Part C - Build a simple dApp that shows actual usage of redux-multicall for data fetching in your dApp: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-c-89a9c11eba76
I am receiving an error when attempting to use Multicall Updater similar to the implementation in uniswap-interface
import React from 'react'
import { combineReducers, createStore } from 'redux'
import { createMulticall } from '@uniswap/redux-multicall'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from '../constants/chains'
import { useInterfaceMulticall } from '../hooks/useContract'
import useBlockNumber from '../contexts/BlockNumberContext'
const multicall = createMulticall()
const reducer = combineReducers({ [multicall.reducerPath]: multicall.reducer })
export default multicall
function getBlocksPerFetchForChainId(chainId): number {
switch (chainId) {
case SupportedChainId.RINKEBY:
case SupportedChainId.ROPSTEN:
return 5
default:
return 1
}
}
export function MulticallUpdater() {
const { chainId } = useWeb3React()
const latestBlockNumber = useBlockNumber()
const contract = useInterfaceMulticall()
const listenerOptions = React.useMemo(
() => ({
blocksPerFetch: getBlocksPerFetchForChainId(chainId),
}),
[chainId]
)
return (
<multicall.Updater
chainId={chainId}
latestBlockNumber={latestBlockNumber}
contract={contract}
listenerOptions={listenerOptions}
/>
)
}
Warning: Cannot update a component (`Updater`) while rendering a different component (`Updater`)
Stack Trace
Warning: Cannot update a component (`Updater`) while rendering a different component (`Updater`). To locate the bad setState() call inside `Updater`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
at Updater
at UpdaterContextBound
at MulticallUpdater
at Updaters
at BlockNumberProvider
at Web3ReactProvider
at UserPreferencesProvider
at Provider
Versions
node v16.8.10
react v18.2.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.