Integrating Leap Wallet
This documentation provides a guide on integrating Leap Wallet into your Aptos/Movement application. By following these steps, you can seamlessly detect, connect, and interact with Leap
Detecting Leap Wallet
To integrate Leap Wallet into your Aptos/Movement application, we recommend using the @aptos-labs/wallet-standard package. This standardised package ensures consistent wallet detection and interaction across different wallet providers.
Prerequisites
Before you begin implementing wallet detection, you'll need to install the required package. Open your terminal and run one of the following commands based on your package manager:
# If you're using npm
npm install @aptos-labs/wallet-standard
# If you're using yarn
yarn add @aptos-labs/wallet-standardImplementing Wallet Detection
Once you've installed the package, you can use the following code snippet to detect available Aptos/Movement wallets, including Leap:
import { getAptosWallets } from '@aptos-labs/wallet-standard'
// Fetch all available Aptos wallets
const wallets = getAptosWallets()
// Access the list of detected wallets
const aptosWallets = wallets.aptosWalletsAfter detecting the wallets, you can find the Leap wallet instance in the aptosWallets object. This will give you access to all wallet functions, including connect, which we'll explore in detail in the following sections.
Alternative Detection Method
You can also access the Leap wallet directly through the window object:
This method provides direct access to the Leap wallet interface when available in the browser environment.
Note: Make sure to implement proper error handling and wallet availability checks in your application to ensure a smooth user experience.
Connecting to Leap Wallet
This section assumes you have completed the wallet detection steps outlined above and have access to the Leap wallet object.
Establishing Connection
To interact with Leap wallet, you'll need to establish a connection first. This will trigger a prompt asking the user for permission to connect your dApp with Leap wallet.
Creating the Wallet Adapter
To ensure seamless interaction, wrap the Leap wallet object with a StandardWalletAdapter:
Note: The networkInfo parameter specifies which Aptos/Movement network to connect to. We'll cover network configuration in detail in the "Network Management" section below.
Disconnecting
To terminate the connection with Leap wallet:
Message Signing
Creating a Sign Message Payload
Before signing a message, create a payload that conforms to the AptosSignMessageInput type:
Signing the Message
Use the adapter's signMessage function to sign your payload:
Transaction Management
Setting Up the Aptos Client
First, initialize the Aptos client with your desired network configuration:
Creating and Signing Transactions
To create a transaction payload:
Option 1: Sign Now, Submit Later
If you need to sign a transaction and submit it later:
Option 2: Sign and Submit Immediately
For immediate signing and submission:
Network Management
The Leap wallet adapter supports dynamic network switching. You can manage networks in two ways:
1. Specify Network During Connection
Pass the network information during the initial connection:
2. Change Network After Connection
Switch networks on an already connected adapter:
Note: The NetworkInfo interface must conform to the specifications from @aptos-labs/wallet-standard.
Last updated