# Solana Wallet Adapter

## Install

{% tabs %}
{% tab title="npm" %}

```bash
npm install @wepin/solana-wallet-adapter
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add @wepin/solana-wallet-adapter
```

{% endtab %}
{% endtabs %}

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`.

<pre class="language-javascript"><code class="lang-javascript"><strong>// 1. Package import
</strong>import { WepinSolanaWalletAdapter } from "@wepin/solana-wallet-adapter";

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

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

```jsx
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

```typescript
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

```typescript
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

```typescript
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);

```

***

### sendTransaction

The `sendTransaction` method accepts a Solana transaction object, signs it, and sends it to the network.

#### parameters

* `transaction` \<Transaction | VersionedTransaction> - The Solana transaction object to sign and send.
* `connection` Connection -The connection object that interacts with the Solana network.
* `options` SendTransactinOptions - Additional options required when sending the transaction. *optional*
  * `signers` - An array of accounts that require additional signatures. *optional*

#### Return Value

* `Promise<TransactionSignature>` - Returns the unique signature of the successfully sent transaction.

#### Example

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

const connection = new Connection(umi.rpc.getEndpoint(), 'finalized')
const publicKey = wepinSolanaWalletAdapter.publicKey

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

//set blockhash and fee payer
transaction.recentBlockhash = 'recent-blockhash';
transaction.feePayer = publicKey;

// transaction sign and send
const signature = await wepinSolanaWalletAdapter.sendTransaction(transaction, connection, {});

console.log('Signature:', signature );

```

***

### signAllTransactions

The `signAllTransactions` method accepts multiple Solana transaction objects and signs them.

{% hint style="info" %}
**The maximum number of transactions that can be signed at once is 10.** Pre-registration is required to use this feature. For registration, [contact Wepin](https://mail.google.com/mail/u/0/?to=wepin.contact@iotrust.kr\&su=Contact+us%5BGeneral%5D\&body=Hello.+Please+enter+your+related+inquiries.\&fs=1\&tf=cm).
{% endhint %}

#### parameters

* `Array<Transaction | VersionedTransaction>`\
  An array of Solana transaction objects to sign.

#### Return Value

* `Promise<Array<Transaction | VersionedTransaction>>`\
  Returns an array of transaction objects with signatures included.

#### Example

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

// sign transactions
const signedTransactions = await wepinSolanaWalletAdapter.signAllTransactions(transactions);

console.log('Signed Transactions:', signedTransactions);

```

***

### disconnect

Disconnects from the Wepin Wallet.

#### parameters

* `<void>`

#### Return Value

* `Promise<void>`

#### Example

```typescript
await wepinWallet.disconnect();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/en/widget-integration/web-javascript-sdk/wallet-adapter/solana-wallet-adapter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
