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

0.2.3 • Public • Published

QtumSnap Connector

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

Usage

Installation

npm install @lukachi/qtum-wallet-snap-connector
yarn add @lukachi/qtum-wallet-snap-connector

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

import { QtumWallet } from '@lukachi/qtum-wallet-snap-connector'

export const qtumSnap = new QtumWallet()

Establish connection

import { qtumSnap } from '@/path/to/qtumSnap'

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

check if snap or metamask is installed

import { isMetamaskInstalled } from '@lukachi/qtum-wallet-snap-connector'

import { qtumSnap } from '@/path/to/qtumSnap'

const checkSnapStatus = async () => {
  return {
    isMetamaskInstalled: await isMetamaskInstalled(),
    isSnapInstalled: await qtumSnap.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 { qtumSnap } from '@/path/to/qtumSnap'

export const useProvider = () => {
  const provider = useMemo(() => {
    try {
      return new providers.Web3Provider(qtumSnap 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 @lukachi/qtum-wallet-snap-connector

Weekly Downloads

1

Version

0.2.3

License

(MIT-0 OR Apache-2.0)

Unpacked Size

241 kB

Total Files

127

Last publish

Collaborators

  • lukachi