@use-web3wallet/cosmos
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

useCosmosWallet

Usage

  1. Install @use-web3wallet/cosmos
yarn add @use-web3wallet/cosmos
// or
npm install --save @use-web3wallet/cosmos
  1. Add CosmosWalletProvider to your DApp
import { CosmosWalletProvider } from "@use-web3wallet/cosmos";

const walletOptions = {
  "Keplr": {
    // Please add chain IDs to support.
    supportedChainIds: [], // ex) ["osmosis-1", "cosmoshub-4", ...]
  }
};

const Index = () => {
  return(
    <CosmosWalletProvider walletOptions={walletOptions}>
      ...
    </CosmosWalletProvider>
  );
}
  1. Use a useCosmosWallet hook
import { useCosmosWallet } from "@use-web3wallet/cosmos";

const Page = () => {
 const {
    connectTo,
    disconnect,
    isLoading,
    isWalletConnected,
    currentWallet,
    provider,
    chainInfos,
  } = useCosmosWallet();

  return (
    <>
      {!isLoading && (
        <>
          {isWalletConnected ? (
            <>
              <button onClick={() => disconnect()}>Disconnect</button>
            </>
          ) : (
            <>
              <button onClick={() => connectTo("Keplr")}>
                Connect to Keplr Wallet
              </button>
            </>
          )}
        </>
      )}
    </>
  );
};

Dependencies (1)

Dev Dependencies (8)

Package Sidebar

Install

npm i @use-web3wallet/cosmos

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

146 kB

Total Files

22

Last publish

Collaborators

  • ryz0nd