@qtumproject/qtum-wallet-connector
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Qtum Wallet Connector

Qtum Wallet connector is used to install snap and exposes methods for calling snap on dApps and other applications.

Usage

Installation

npm install @qtumproject/qtum-wallet-connector
yarn add @qtumproject/qtum-wallet-connector

Define raw provider (object which is similar to window.ethereum)

import { QtumWallet } from '@qtumproject/qtum-wallet-connector';

export const qtumWallet = new QtumWallet();

Establish connection

import { qtumWallet } from '@/path/to/qtumWallet';

const init = async () => {
  await qtumWallet.enable();
};

Check if snap or metamask is installed

import { isMetamaskInstalled } from '@qtumproject/qtum-wallet-connector';

import { qtumWallet } from '@/path/to/qtumWallet';

const checkSnapStatus = async () => {
  return {
    isMetamaskInstalled: await isMetamaskInstalled(),
    isSnapInstalled: await qtumWallet.isInstalled(),
  };
};

After that it can be used as provider inside ethers.js

Example

import { ethers } from 'ethers';

const provider = new ethers.providers.Web3Provider(connector);

React example

import { providers } from 'ethers';
import { useMemo } from 'react';

import { qtumWallet } from '@/path/to/qtumWallet';

export const useProvider = () => {
  const provider = useMemo(() => {
    try {
      return new providers.Web3Provider(
        qtumWallet as providers.ExternalProvider,
      );
    } catch (error) {
      return undefined;
    }
  }, []);

  const signer = useMemo(() => {
    return provider?.getSigner();
  }, [provider]);

  return {
    provider,
    signer,
  };
};

Readme

Keywords

none

Package Sidebar

Install

npm i @qtumproject/qtum-wallet-connector

Weekly Downloads

11

Version

0.2.0

License

(MIT-0 OR Apache-2.0)

Unpacked Size

214 kB

Total Files

111

Last publish

Collaborators

  • dl_kyrylo
  • alejoacosta