@avalabs/avalanche-connector
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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 coreintegrations@avalabs.org

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();
}

Readme

Keywords

none

Package Sidebar

Install

npm i @avalabs/avalanche-connector

Weekly Downloads

7

Version

1.0.0

License

MIT

Unpacked Size

45.9 kB

Total Files

22

Last publish

Collaborators

  • meeh0w_ava
  • glovas