Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@avalabs/web3-react-core-connector

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/web3-react-core-connector

Core Extension connector for the web3-react library

  • 1.1.1-alpha.0
  • alpha
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-16.67%
Maintainers
2
Weekly downloads
 
Created
Source

Core extension web3-react Connector

Core Extension connector for web3-react.

Getting started

There is a working example in this repo under the package web3-react-dapp-example

import { createContext, useContext } from 'react';
import { initializeConnector, Web3ReactHooks } from '@web3-react/core';
import { CoreWallet } from '@avalabs/web3-react-core-connector';

const Web3ConnectionContext = createContext<
  {
    connector: CoreWallet;
  } & Web3ReactHooks
>({} as any);

export function Web3ConnectionContextProvider({ children }: { children: any }) {
  const [error, setError] = useState<Error | undefined>();
  const [connector, hooks] = initializeConnector(
    (actions) =>
      new CoreWallet({
        actions,
        onError: (e: Error) => {
          console.error('Core Connector error', e);
          setError(e);
        },
      })
  );

  return (
    <Web3ConnectionContext.Provider
      value={{
        connector,
        error,
        ...hooks,
      }}
    >
      {children}
    </Web3ConnectionContext.Provider>
  );
}

export function useWeb3ConnectionContext() {
  return useContext(Web3ConnectionContext);
}
<Web3ConnectionContextProvider>
  <App />
</Web3ConnectionContextProvider>
import { useWeb3ConnectionContext } from 'your-path-here';

export function YourFancyComponent() {
  const { connector, useIsActive, useAccount } = useWeb3ConnectionContext();
  const isActive = useIsActive();
  const activeAccount = useAccount();

  if (!isActive) {
    return (
      <button
        onClick={() => connector.activate().catch((e) => console.error(e))}
      >
        Connect with Core
      </button>
    );
  }

  return (
    <div>
      <strong>Connected:</strong> {activeAccount}
    </div>
  );
}

Keywords

FAQs

Package last updated on 14 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc