WalletAdapter.js
that defines a new WalletAdapter
React component that renders the components of your app.
We use this component to set up the adapters for each Solana wallet we want to support.
WalletAdapter.js
file, import the WalletModalProvider
and the default CSS styles from the @solana/wallet-adapter-react-ui
package. Wrap the WalletModalProvider
around your app’s components.
WalletProvider
component.
In your WalletAdapter.js
file, import the WalletProvider
component from the @solana/wallet-adapter-react
package. Wrap the WalletProvider
component around the WalletModalProvider
component.
WalletProvider
component accepts a list of wallets as a prop. To add wallets, import adapters from the @solana/wallet-adapter-wallets
package for each wallet you want to support, and pass a list of the wallet adapters as a prop into the WalletProvider
component.
autoconnect
attribute on the WalletProvider
component to automatically attempt to reconnect a user wallet upon a page refresh.ConnectionProvider
component.
In your WalletAdapter.js
file, import the ConnectionProvider
component from the @solana/wallet-adapter-react
package. Wrap the ConnectionProvider
component around the WalletProvider
component.
ConnectionProvider
component accepts a network endpoint as a prop. You can set your network to devnet
, testnet
, mainnet-beta
, or provide a custom RPC endpoint.
WalletConnectButton
and WalletDisconnectButton
components respectively, or the WalletMultiButton
component which enables connecting and disconnecting using a single button. For this guide, we use WalletMultiButton
.
In your App.js
file, import the WalletMultiButton
component from the @solana/wallet-adapter-react-ui
package. Include the WalletMultiButton
component alongside the other components of your app.
useWallet()
React hook to get a user’s public key, check connection status of their wallet, as well as sign messages and send transactions on their behalf.
In your App.js
file, import the userWallet
React hook from the @solana/wallet-adapter-react
package, and use it to access the user’s public key and other methods like sendTransaction
.