Skip to content

xmtp-labs/xmtp-quickstart-privy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XMTP Privy Quickstart

xmtp

Installation

yarn install
yarn dev

Concepts

Head to our docs to understand XMTP's concepts

Troubleshooting

If you get into issues with Buffer and polyfills check out the fix below:

Privy

Setup

First, you need to import the necessary libraries and components. In your index.js file, import the PrivyProvider from @privy-io/react-auth and wrap your main component with it.

import { PrivyProvider } from "@privy-io/react-auth";
<PrivyProvider
appId={process.env.REACT_APP_PRIVY_APP_ID}
onSuccess={(user) => console.log(User ${user.id} logged in!)}
>
<InboxPage />
</PrivyProvider>

User authentication

In your main component, use the usePrivy hook to get the user's authentication status and other details.

const { ready, authenticated, user, login, logout } = usePrivy();

Wallet integration

Use the useWallets hook to get the user's wallets. Then, find the embedded wallet and set it as the signer.

useEffect(() => {
  const getSigner = async () => {
    const embeddedWallet =
      wallets.find((wallet) => wallet.walletClientType === "privy") ||
      wallets[0];
    if (embeddedWallet) {
      const provider = await embeddedWallet.getEthersProvider();
      setSigner(provider.getSigner());
    }
  };

  if (wallets.length > 0) {
    getSigner();
  }

XMTP Integration

In your Home component, use the useClient hook from @xmtp/react-sdk to get the XMTP client.

const { client, error, isLoading, initialize } = useClient();

That's it! You've now created an XMTP app with Privy.

About

xmtp-quickstart-privy

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published