npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

larry-wallet-adapter-react

v1.1.1

Published

Aptos Wallet Adapter React Provider

Downloads

2

Readme

Wallet Adapter React Provider

A react provider wrapper for the Aptos Wallet Adapter

Dapps that want to use the adapter should install this package and other supported wallet packages.

Support

The react provider supports all wallet standard functions and feature functions

Standard functions
connect
disconnect
connected
account
network
signAndSubmitTransaction
signMessage
Feature functions
signTransaction
signMessageAndVerify

Usage

Install Dependencies

Install wallet dependencies you want to include in your app. To do that, you can look at our supported wallets list. Each wallet is a link to npm package where you can install it from.

Next, install the @aptos-labs/wallet-adapter-react

pnpm i @aptos-labs/wallet-adapter-react

using npm

npm i @aptos-labs/wallet-adapter-react

Import dependencies

On the App.jsx file,

Import the installed wallets.

import { SomeAptosWallet } from "some-aptos-wallet-package";

Import the AptosWalletAdapterProvider.

import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";

Wrap your app with the Provider, pass it the plugins (wallets) you want to have on your app as an array and a autoConnect option (set to false by default)

const wallets = [new AptosWallet()];

<AptosWalletAdapterProvider plugins={wallets} autoConnect={true}>
  <App />
</AptosWalletAdapterProvider>;

Use Wallet

On any page you want to use the wallet props, import useWallet from @aptos-labs/wallet-adapter-react

import { useWallet } from "@aptos-labs/wallet-adapter-react";

Then you can use the exported properties

const {
  connect,
  account,
  network,
  connected,
  disconnect,
  wallet,
  wallets,
  signAndSubmitTransaction,
  signTransaction,
  signMessage,
  signMessageAndVerify,
} = useWallet();

Use a UI package (recommended)

As part of the wallet adapter repo we provide a wallet connect UI package that provides a wallet connect button and a wallet select modal. You can find it here with instructions on how to use it.

Examples

connect(walletName)
<button onClick={() => connect(wallet.name)}>{wallet.name}</button>
disconnect()
<button onClick={disconnect}>Disconnect</button>
signAndSubmitTransaction(payload)
  const onSignAndSubmitTransaction = async () => {
    const payload: Types.TransactionPayload = {
      type: "entry_function_payload",
      function: "0x1::coin::transfer",
      type_arguments: ["0x1::aptos_coin::AptosCoin"],
      arguments: [account?.address, 1], // 1 is in Octas
    };
    try {
      const response = await signAndSubmitTransaction(payload);
      // if you want to wait for transaction
      await aptosClient.waitForTransaction(response?.hash || "");
      console.log(response?.hash)
    } catch (error: any) {
      console.log("error", error);
    }
  };

<button onClick={onSignAndSubmitTransaction}>
  Sign and submit transaction
</button>
signMessage(payload)
  const onSignMessage = async () => {
    const payload = {
      message: "Hello from Aptos Wallet Adapter",
      nonce: "random_string",
    };
    try {
      const response = await signMessage(payload);
      console.log("response", response);
    } catch (error: any) {
      console.log("error", error);
    }
  };

<button onClick={onSignMessage}>
  Sign message
</button>
Account
<div>{account?.address}</div>
<div>{account?.publicKey}</div>
Network
<div>{network?.name}</div>
Wallet
<div>{wallet?.name}</div>
<div>{wallet?.icon}</div>
<div>{wallet?.url}</div>
Wallets
{
  wallets.map((wallet) => <p>{wallet.name}</p>);
}
signTransaction(payload)
  const onSignTransaction = async () => {
    const payload: Types.TransactionPayload = {
      type: "entry_function_payload",
      function: "0x1::coin::transfer",
      type_arguments: ["0x1::aptos_coin::AptosCoin"],
      arguments: [account?.address, 1], // 1 is in Octas
    };
    try {
      const response = await signTransaction(payload);
      console.log("response", response);
    } catch (error: any) {
      console.log("error", error);
    }
  };

<button onClick={onSignTransaction}>
  Sign transaction
</button>
signMessageAndVerify(payload)
const onSignMessageAndVerify = async () => {
  const payload = {
    message: "Hello from Aptos Wallet Adapter",
    nonce: "random_string",
  };
  try {
    const response = await signMessageAndVerify(payload);
    console.log("response", response);
  } catch (error: any) {
    console.log("error", error);
  }
};

<button onClick={onSignMessageAndVerify}>
  Sign message and verify
</button>