Solana Wallet Adapter

@wepin/solana-wallet-adapter is designed to interact with the Solana blockchain, providing an easy-to-use Wallet Adapter based on @solana/wallet-adapter-base.

Install

npm install @wepin/solana-wallet-adapter

Once the installation is complete, initialize the WepinSolanaWalletAdapter instance using the app ID and app key assigned after registering the app. This will enable the use of WepinSolanaWalletAdapter.

// 1. Package import
import { WepinSolanaWalletAdapter } from "@wepin/solana-wallet-adapter";


// 2. Initialize
const wepinSolanaWalletAdapter = new WepinSolanaWalletAdapter({
    appId: 'your-wepin-app-id',
    appKey: 'your-wepin-app-key',
    network: 'solana',
    attributes: {
        defaultCurrency: 'KRW', 
        defaultLanguage: 'ko'
    }
})

If you're using @solana/wallet-adapter-react, initialize the adapter as shown below:

const wallets = useMemo(
    () => [
      new WepinSolanaWalletAdapter({
        appId: 'your-wepin-app-id',
        appKey: 'your-wepin-app-key',
        network: 'solana',
        attributes: {
            defaultCurrency: 'KRW', 
            defaultLanguage: 'ko'
        }
      })
    ],
    []
  );

Parameters

WepinWalletAdapterConfig <Object>

  • appId <string> The App ID assigned after application registration.

  • appKey <string> The App Key assigned after application registration.

  • network <string> (optional) The network variable for the supported wallet adapter. For Solana Mainnet, use "solana". Must be entered in lowercase. Default is "solana".

  • attributes <object> (optional)

    • defaultLanguage: Sets the widget's default language. Supported languages are en, ko, and ja. Default is en.

    • defaultCurrency: Sets the widget's default currency. Supported currencies are USD, KRW, and JPY. Default is USD.

Methods

The following methods are available in the WepinSolanaWalletAdapter.

connect

Connects to the Wepin Wallet and retrieves the user's Public Key.

parameters

  • <void>

Return Value

Promise<void>

  • On successful connection, the adapter's connected property will be set to true, and the publicKey property will hold the user's Public Key.

Example

await walletSolanaWalletAdapter.connect()
const isConnected = walletSolanaWalletAdapter.connected    // Check connection status
const publicKey = walletSolanaWalletAdapter.publicKey        // Get connected account's Public Key

signMessage

Signs a given message using the user's private key.

parameters

  • message <Uint8Array> The message to sign.

Return Value

  • Promise<Uint8Array> The signed message as a Uint8Array.

Example

const message = new TextEncoder().encode('Hello, Solana!');
const signedMessage = await wepinSolanaWalletAdapter.signMessage(message);
console.log(`Signed message as Uint8Array:`, signedMessage);

signTransaction

Signs a Solana transaction object.

parameters

  • <Transaction | VersionedTransaction> The Solana transaction object to sign.

Return Value

  • Promise<Transaction | VersionedTransaction> The signed transaction object.

Example

import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js';

const publicKey = wepinSolanaWalletAdapter.publicKey
// Create a transaction
const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: publicKey,
    toPubkey: new PublicKey('recipient-public-key'),
    lamports: 1000000,
  }),
);

// Set recent blockhash and feePayer
transaction.recentBlockhash = 'recent-blockhash';
transaction.feePayer = publicKey;

// Sign the transaction
const signedTransaction = await wepinSolanaWalletAdapter.signTransaction(transaction);

console.log('Signed Transaction:', signedTransaction);

disconnect

Disconnects from the Wepin Wallet.

parameters

  • <void>

Return Value

  • Promise<void>

Example

await wepinWallet.disconnect();

Last updated