This documentation provides a guide on integrating Leap Wallet into your Solana application. By following these steps, you can seamlessly detect, connect, and interact with Leap.
Detecting Leap Wallet
To seamlessly integrate Leap Wallet into your Solana application, use the @wallet-standard/core package. This standardized approach ensures consistent wallet detection and interaction across different providers.
Prerequisites
Before you begin, install the required package using your preferred package manager:
# Using NPMnpmi@wallet-standard/core# Using Yarnyarnadd@wallet-standard/core
Implementing Wallet Detection
After installing the package, use the following code snippet to detect Solana-compatible wallets, including Leap:
import { getWallets } from'@wallet-standard/core'const { get } =getWallets()constallWallets=get()
Next, filter out any wallets that are not compatible with the solana standard.
Once you've identified the Leap wallet within the solanaWallets array, you'll gain access to various functions like connect, which we’ll cover in the next section.
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.
Enable Connection
The wallet connection can be established using the connect method. If the wallet is locked, it will redirect to the extension login page. If the user hasn't permitted the webpage, it will ask for permission.
Disconnect
Disconnect the wallet from the dApp.
Sign In
Authenticate with a dApp using Sign In with Solana.
Sign Message
Sign an arbitrary message.
Sign Transaction
Sign a transaction without broadcasting it.
Sign and Send Transaction
Sign and broadcast a transaction to the network.
Change Network
Switch between different Solana networks.
Example Usage with Web3.js
Events
The wallet provider emits events that you can listen to:
Note: All methods may throw errors if the wallet is locked, user rejects the request, or if there are network issues. Make sure to implement proper error handling in your dApp.
Last updated
const leapWallet = window.leap?.solana
import { StandardConnectOutput } from '@wallet-standard/base';
const { accounts }: StandardConnectOutput = await window.leap.solana.connect({
silent?: boolean // Optional: If true, won't prompt if already connected
});
await window.leap.solana.disconnect() // void function
import { SolanaSignInInput, SolanaSignInOutput } from '@solana/wallet-standard-features';
const input: SolanaSignInInput[] = {
domain: string, // The domain requesting sign in
statement?: string, // Optional statement to display
uri?: string, // Optional URI
version?: string, // Optional version
chainId?: string, // Optional chain ID
nonce?: string, // Optional nonce
issuedAt?: string, // Optional issuance timestamp
expirationTime?: string, // Optional expiration time
notBefore?: string, // Optional not-before time
requestId?: string, // Optional request ID
resources?: string[] // Optional array of resources
};
const result: SolanaSignInOutput[] = await window.leap.solana.signIn(input);
// Returns { account: WalletAccount, signedMessage: Uint8Array, signature: Uint8Array }
import { SolanaSignMessageInput, SolanaSignMessageOutput } from '@solana/wallet-standard-features';
import type { WalletAccount } from '@wallet-standard/base';
const input: SolanaSignMessageInput[] = {
message: Uint8Array, // The message to sign
account: WalletAccount // The account to sign with
};
const signed: SolanaSignMessageOutput[] = await window.leap.solana.signMessage(input);
// Returns { signedMessage: Uint8Array, signature: Uint8Array }
import { SolanaSignTransactionInput, SolanaSignTransactionOutput, SolanaSignTransactionOptions } from '@solana/wallet-standard-features';
import type { WalletAccount, IdentifierString } from '@wallet-standard/base';
const input: SolanaSignTransactionInput[] = {
transaction: Uint8Array, // The transaction to sign
account: WalletAccount, // The account to sign with
chain?: IdentifierString // Optional: defaults to 'solana:mainnet'
options?: SolanaSignTransactionOptions {
// Optional transaction options
}
};
const signed: SolanaSignTransactionOutput[] = await window.leap.solana.signTransaction(input);
// Returns { signedTransaction: Uint8Array }
import { SolanaSignAndSendTransactionInput, SolanaSignAndSendTransactionOutput } from '@solana/wallet-standard-features';
import type { WalletAccount } from '@wallet-standard/base';
const input: SolanaSignAndSendTransactionInput = {
transaction: Uint8Array, // The transaction to sign and send
account: WalletAccount, // The account to sign with
chain: IdentifierString, // The chain to broadcast transaction
options?: {
// Optional transaction options
}
};
const result: SolanaSignAndSendTransactionOutput = await window.leap.solana.signAndSendTransaction(input);
// Returns { signature: Uint8Array }