Qtum Wallet connector is used to install snap and exposes methods for calling snap on dApps and other applications.
npm install @qtumproject/qtum-wallet-connector
yarn add @qtumproject/qtum-wallet-connector
import { QtumWallet } from '@qtumproject/qtum-wallet-connector';
export const qtumWallet = new QtumWallet();
import { qtumWallet } from '@/path/to/qtumWallet';
const init = async () => {
await qtumWallet.enable();
};
import { isMetamaskInstalled } from '@qtumproject/qtum-wallet-connector';
import { qtumWallet } from '@/path/to/qtumWallet';
const checkSnapStatus = async () => {
return {
isMetamaskInstalled: await isMetamaskInstalled(),
isSnapInstalled: await qtumWallet.isInstalled(),
};
};
import { ethers } from 'ethers';
const provider = new ethers.providers.Web3Provider(connector);
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,
};
};