Skip to Content
React SDKSolana Provider
View .md

Solana Provider

The @alien-id/miniapps-solana-provider package provides a wallet-standard compatible Solana wallet for mini apps. It bridges the Alien app’s native wallet to any Solana dApp stack (wallet adapters, Anchor, web3.js, etc.).

It currently works only when your mini app runs inside the Alien app WebView. If the bridge is unavailable, initAlienWallet() exits without registering the wallet.

Installation

npm install @alien-id/miniapps-solana-provider

Quick Start

Call initAlienWallet() once at your app’s entry point. Wallet adapters will auto-discover the Alien wallet.

import { initAlienWallet } from '@alien-id/miniapps-solana-provider'; // Register at app startup (e.g., main.tsx) initAlienWallet();

That’s it — your existing Solana wallet adapter code will see “Alien” as an available wallet.

How It Works

Your dApp (wallet adapter) ↓ wallet-standard discovery AlienSolanaWallet ↓ bridge requests Alien App (native wallet)
  1. initAlienWallet() registers an AlienSolanaWallet instance via @wallet-standard/wallet
  2. Wallet adapters (e.g., @solana/wallet-adapter-react) auto-discover it
  3. All wallet operations (connect, sign, send) go through the bridge to the Alien app’s native wallet

Requirements

  • Bridge must be available (running inside the Alien app)
  • Contract version 1.0.0 or higher
  • If the bridge is unavailable, initAlienWallet() returns without registering
  • If the contract version is too old, initAlienWallet() logs a warning and does not register

Features

The wallet implements these wallet-standard features:

FeatureDescription
standard:connectConnect to the wallet
standard:disconnectDisconnect from the wallet
standard:eventsListen for account changes
solana:signTransactionSign a transaction
solana:signAndSendTransactionSign and send a transaction
solana:signMessageSign an arbitrary message

Supported transaction versions: legacy and 0.

Supported chains: solana:mainnet, solana:devnet, solana:testnet.

Usage with Wallet Adapter

import { ConnectionProvider, WalletProvider, } from '@solana/wallet-adapter-react'; import { initAlienWallet } from '@alien-id/miniapps-solana-provider'; // Register before rendering initAlienWallet(); function App() { return ( <ConnectionProvider endpoint={rpcUrl}> <WalletProvider wallets={[]} autoConnect> <YourApp /> </WalletProvider> </ConnectionProvider> ); }

Pass an empty wallets array — the Alien wallet is discovered automatically via wallet-standard. No manual adapter needed.

Error Handling

Wallet operations throw AlienWalletError on failure.

import { AlienWalletError } from '@alien-id/miniapps-solana-provider'; try { await wallet.connect(); } catch (error) { if (error instanceof AlienWalletError) { console.error(error.code, error.message); } }

Error Codes

CodeNameDescription
5000USER_REJECTEDUser rejected the request
-32602INVALID_PARAMSInvalid request parameters
-32603INTERNAL_ERRORInternal wallet error
8000REQUEST_EXPIREDRequest timed out (60s)

Named constants are available from @alien-id/miniapps-contract:

import { WALLET_ERROR } from '@alien-id/miniapps-contract'; if (error.code === WALLET_ERROR.USER_REJECTED) { // User cancelled }

API Reference

initAlienWallet

function initAlienWallet(): void;

Registers the Alien wallet with wallet-standard. Call once at app startup. Safe to call multiple times (idempotent). Does nothing if the bridge is unavailable or the contract version doesn’t support wallet methods.

AlienSolanaWallet

The wallet-standard Wallet implementation. You typically don’t interact with this directly — wallet adapters handle it.

class AlienSolanaWallet implements Wallet { readonly version: '1.0.0'; readonly name: 'Alien'; readonly chains: ['solana:mainnet', 'solana:devnet', 'solana:testnet']; readonly accounts: readonly WalletAccount[]; readonly features: { /* see Features table */ }; }

AlienSolanaAccount

Represents a connected Solana account.

class AlienSolanaAccount implements WalletAccount { readonly address: string; // Base58 public key readonly publicKey: Uint8Array; readonly chains: SolanaChain[]; readonly features: string[]; }

AlienWalletError

Error class with a numeric code property matching wallet error codes.

class AlienWalletError extends Error { readonly code: WalletSolanaErrorCode; }

Next Steps

Last updated on