wallet-gaya-sdk
v1.0.9
Published
SDK to connect and interact with Gaya Wallet easily in web apps.
Readme
Gaya Wallet SDK
A lightweight JavaScript/TypeScript SDK to easily connect to Gaya Wallet and detect Gaya Wallet installation in web applications.
✨ Features
- Check if Gaya Wallet is installed
- Connect to Gaya Wallet
- Get the connected wallet address
- Sign a message with Gaya Wallet
- Check if wallet is currently connected
- Disconnect the wallet
- Send a transaction using Gaya Wallet
📦 Installation
Using npm:
npm install wallet-gaya-sdkUsing pnpm:
pnpm add wallet-gaya-sdkUsing yarn:
yarn add wallet-gaya-sdk🚀 Usage
Import the SDK functions:
import {
isGayaWalletInstalled,
connectGayaWallet,
getGayaWalletAddress,
signMessageWithGayaWallet,
isWalletConnected,
disconnectWallet,
sendTransaction,
} from "wallet-gaya-sdk";1. Check if Gaya Wallet is Installed
if (isGayaWalletInstalled()) {
console.log("Gaya Wallet is installed.");
} else {
console.log("Gaya Wallet is not installed.");
}2. Connect to Gaya Wallet
try {
const wallet = await connectGayaWallet();
console.log("Wallet connected:", wallet);
} catch (error) {
console.error("Error connecting to Gaya Wallet:", error);
}3. Get Connected Wallet Address
try {
const address = await getGayaWalletAddress();
console.log("Connected wallet address:", address);
} catch (error) {
console.error("Error fetching wallet address:", error);
}4. Sign Message with Gaya Wallet
try {
const message = "Hello Solana World! Please sign me.";
const signed = await signMessageWithGayaWallet(message);
console.log("Signed message:", signed);
} catch (error) {
console.error("Error signing message:", error);
}5. Check if Wallet is Connected
const isConnected = await isWalletConnected();
console.log("Is wallet connected?", isConnected);6. Disconnect Wallet
try {
await disconnectWallet();
console.log("Wallet disconnected.");
} catch (error) {
console.error("Error disconnecting wallet:", error);
}7. Send Transaction with Gaya Wallet
try {
const transaction = "base64_or_serialized_transaction_data";
const txResult = await sendTransaction(transaction);
console.log("Transaction result:", txResult);
} catch (error) {
console.error("Error sending transaction:", error);
}📚 API Reference
isGayaWalletInstalled(): boolean
- Checks if Gaya Wallet is available in the browser.
- Returns:
trueif installed, otherwisefalse.
connectGayaWallet(): Promise<any>
- Initiates a connection request to Gaya Wallet.
- Returns: Wallet connection result or throws an error if connection fails.
getGayaWalletAddress(): Promise<string | null>
- Retrieves the currently connected wallet address.
- Returns: Address as a
string, ornullif not connected.
signMessageWithGayaWallet(message: string): Promise<{ address: string; message: string; signature: string } | null>
- Requests Gaya Wallet to sign a message.
- Returns: Signed object including address, message, and signature, or
nullif failed.
isWalletConnected(): Promise<boolean>
- Checks if the wallet is currently connected.
- Returns:
trueif connected,falseotherwise.
disconnectWallet(): Promise<void>
- Disconnects the wallet if connected.
- Returns:
void
sendTransaction(transaction: string): Promise<any>
- Sends a transaction through Gaya Wallet.
- Returns: Response from the wallet provider or
nullif failed.
📄 License
This project is licensed under the MIT License.
