@avalabs/avalanche-connector
v1.0.0
Published
This is a connector for the upcoming release of `@web3-react/core`. This serves as an example of how to connect for versions older than `8.0.17-beta.0`. If you need help connecting to older versions feel free to reach out at `[email protected]`
Downloads
33
Keywords
Readme
Avalanche Connector
This is a connector for the upcoming release of @web3-react/core
. This serves as an example of how to connect for versions older than 8.0.17-beta.0
. If you need help connecting to older versions feel free to reach out at [email protected]
Getting started
There is a working example in this repo under the package avalanche connector example
import { createContext, useContext } from 'react';
import { initializeConnector, Web3ReactHooks } from '@web3-react/core';
import { Avalanche } from '@avalabs/avalanche-connector';
const Web3ConnectionContext = createContext<
{
connector: Avalanche;
} & Web3ReactHooks
>({} as any);
export function Web3ConnectionContextProvider({ children }: { children: any }) {
const [connector, hooks] = initializeConnector(
(actions) => new Avalanche(actions, true)
);
return (
<Web3ConnectionContext.Provider
value={{
connector,
...hooks,
}}
>
{children}
</Web3ConnectionContext.Provider>
);
}
export function useWeb3ConnectionContext() {
return useContext(Web3ConnectionContext);
}
<Web3ConnectionContextProvider>
<App />
</Web3ConnectionContextProvider>
import { useWeb3ConnectionContext } from 'your-path-here';
export function YourFancyComponent() {
const { provider, hooks } = useWeb3ConnectionContext();
}