Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
eosconsequatur
Advanced tools
A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
web3-react
DocumentationGrab yourself a fresh copy of react@>=16.8
yarn add react@latest
And then install web3-react
yarn add @web3-react/core@latest
web3-react
Contextinterface Web3ReactContextInterface<T = any> {
activate: (
connector: AbstractConnectorInterface,
onError?: (error: Error) => void,
throwErrors?: boolean
) => Promise<void>
setError: (error: Error) => void
deactivate: () => void
connector?: AbstractConnectorInterface
library?: T
chainId?: number
account?: null | string
active: boolean
error?: Error
}
web3-react@core
API Referenceweb3-react
relies on the existence of a Web3ReactProvider
at the root of your dApp (or the subtree which you'd like to have web3 functionality).
getLibrary: (provider: any) => any
import { Web3ReactProvider } from '@web3-react/core'
// ...
function getLibrary(provider) {
return new Web3Provider(provider) // this will vary acccording to the web3 convenience library you use
}
function App () {
return (
<Web3ReactProvider getLibrary={getLibrary}>
{/* <...> */}
</Web3ReactProvider>
)
}
In some cases, a dApp may want to maintain >1 active web3 connections simultaneously. This could be for any number of reasons, including:
In cases like these, you'll likely want to create a second (or maybe even third third, but probably not fourth) root, which will function exactly like another Web3ReactProvider (in fact, Web3ReactProvider uses createWeb3ReactRoot under the hood).
key: string
import { Web3ReactProvider, createWeb3ReactRoot } from '@web3-react/core'
// ...
function getLibrary(provider) {
return new Web3Provider(provider) // this will vary acccording to the web3 convenience library used
}
const Web3ReactProviderReloaded = createWeb3ReactRoot('anotherOne')
function App () {
return (
<Web3ReactProvider getLibrary={getLibrary}>
<Web3ReactProviderReloaded getLibrary={getLibrary}>
{/* <...> */}
</Web3ReactProviderReloaded>
</Web3ReactProvider>
)
}
If you're using Hooks (😇), useWeb3React is your best friend. Call it from within any function component to access the web3-react
Context. Just like that.
key?: string
import { useWeb3React } from '@web3-react/core'
function Component () {
const web3React = useWeb3React()
// ...
}
If you're not using Hooks (😳), getWeb3ReactContext is your savior. It will give you direct access to the context returned by createContext
, which will unlock the use of contextType
in class components, the Context.Consumer
pattern, or whatever other render prop/HOC/etc. shenanigans your manager whose personal site still runs on PHP is making you write.
key?: string
import { getWeb3ReactContext } from '@web3-react/core'
const web3ReactContext = getWeb3ReactContext()
This is an error which can be used to inform users that they're connected to an unsupported network.
import { UnsupportedChainIdError } from '@web3-react/core'
// ...
function Component () {
const { error } = useWeb3React()
const isUnsupportedChainIdError = error instanceof UnsupportedChainIdError
// ...
}
FAQs
A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
The npm package eosconsequatur receives a total of 61 weekly downloads. As such, eosconsequatur popularity was classified as not popular.
We found that eosconsequatur demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.