# SOL Pay

An easy-to-use web SDK and API to start accepting non-custodial Solana payments in under 5 minutes!

## Welcome to the SOL Pay Docs

Welcome to the SOL Pay Docs! Here you'll find all the documentation you need to get up and running with the SOL Pay SDK and API and start accepting non-custodial Solana payments in under 5 minutes!

## Want to jump right in?

Jump in to the quick start docs and get started right away:

{% content-ref url="/pages/q36HZ64Y2I3dNxEF9sQm" %}
[Quick Start](/quick-start)
{% endcontent-ref %}

{% content-ref url="/pages/JxIsmS8iKzrZEPdzbOZm" %}
[Streams](/streams)
{% endcontent-ref %}

## Want to deep dive?

Dive a little deeper and start exploring our SDK and API references to get an idea of everything that's possible with the SOL Pay:

{% content-ref url="/pages/UgxHW4O06STBY539kSYr" %}
[SDK Reference](/reference/sdk-reference)
{% endcontent-ref %}

{% content-ref url="/pages/jOkX0bXoTFLOAqXXbEFj" %}
[API Reference](/reference/api-reference)
{% endcontent-ref %}


# Quick Start

Get started with the SDK in under 5 minutes!

## Import the SDK

{% tabs %}
{% tab title="index.html" %}

```html
<script src="https://solpay.solblaze.org/sdk.js" type="text/javascript"></script>
```

{% endtab %}
{% endtabs %}

## Connect to the Solana Network

### Connect to Default RPC Endpoint:

{% tabs %}
{% tab title="index.js" %}

```javascript
(async () => {
    let network_details = await SOLPay.connectNetwork();
    console.log(network_details.network); // default network RPC URL
    console.log(network_details.commitment); // "confirmed"
})();
```

{% endtab %}
{% endtabs %}

### Connect to Custom RPC Endpoint:

{% tabs %}
{% tab title="index.js" %}

```javascript
(async () => {
    let network_details = await SOLPay.connectNetwork("https://api.mainnet-beta.solana.com", "confirmed");
    console.log(network_details.network); // "https://api.mainnet-beta.solana.com"
    console.log(network_details.commitment); // "confirmed"
})();
```

{% endtab %}
{% endtabs %}

## Connect Wallet

{% tabs %}
{% tab title="index.js" %}

```javascript
(async () => {
    let wallet = await SOLPay.connectWallet(SOLPay.adapters.PHANTOM);
    console.log(wallet.address); // the address of the connected wallet
})();
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}

#### Wallet Adapters:

SOL Pay supports six wallets:

* Phantom (`SOLPay.adapters.PHANTOM`)
* Solflare (`SOLPay.adapters.SOLFLARE`)
* Slope (`SOLPay.adapters.SLOPE`)
* Glow (`SOLPay.adapters.GLOW`)
* Exodus (`SOLPay.adapters.EXODUS`)
* Brave (`SOLPay.adapters.BRAVE`)

You can also use `SOLPay.adapters.CURRENT_ADAPTER` or leave the adapter field blank to use the current adapter.
{% endhint %}

## Send Transaction

### Send Solana Lamports

{% tabs %}
{% tab title="index.js" %}

```javascript
(async () => {
    let address = "RECIPIENT_ADDRESS_HERE" // replace with the Solana address of the recipient
    let lamports = 10000; // replace with the number of lamports to send, one billion lamports per SOL
    let payment_details = await SOLPay.sendSolanaLamports(address, lamports);
    console.log(payment_details.from); // the address of the sender wallet/connected wallet
    console.log(payment_details.to); // the address of the recipient wallet
    console.log(payment_details.lamports); // the lamports transacted
    console.log(payment_details.signature); // the signature of the transaction
})();
```

{% endtab %}
{% endtabs %}

### Send Solana

{% hint style="warning" %}

#### Important:

This method may lead to slightly inaccurate results due to decimal roundoff error. We highly recommend using the sendSolanaLamports method (shown above) instead.
{% endhint %}

{% tabs %}
{% tab title="index.js" %}

```javascript
(async () => {
    let address = "RECIPIENT_ADDRESS_HERE" // replace with the Solana address of the recipient
    let amount = 0.00001; // replace with the amount of SOL to send
    let payment_details = await SOLPay.sendSolana(address, amount);
    console.log(payment_details.from); // the address of the sender wallet/connected wallet
    console.log(payment_details.to); // the address of the recipient wallet
    console.log(payment_details.lamports); // the lamports transacted
    console.log(payment_details.signature); // the signature of the transaction
})();
```

{% endtab %}
{% endtabs %}

## Verify Transaction

{% hint style="warning" %}

#### Important:

It is vital to verify that a transaction is valid on your backend. If you only trust the payment details on the front-end, hackers can easily forge fake transactions. However, verifying the transaction on your backend resolves this issue. The backend is also where you would complete the transaction by logging the signature to a database (so that it cannot be used twice) and then providing the user with the product.

Our API does not check whether you have already verified a transaction. You need to make sure on your backend that you are storing the transaction signatures so that they cannot be used to buy the same product twice.
{% endhint %}

## Verifies the details of a transaction made through SOL Pay

<mark style="color:blue;">`GET`</mark> `https://solpay.solblaze.org/transaction.php`

The transaction endpoint takes in two parameters: to and txid. The to parameter is for the recipient address, and the txid is for the signature (which can be obtained through the payment details above). The endpoint returns the sender address and the number of lamports sent.

#### Query Parameters

| Name                                   | Type   | Description           |
| -------------------------------------- | ------ | --------------------- |
| to<mark style="color:red;">\*</mark>   | string | recipient address     |
| txid<mark style="color:red;">\*</mark> | string | transaction signature |

{% tabs %}
{% tab title="200: OK The transaction details are returned" %}

```javascript
{
    "status": "success",
    "transaction": {
        "lamports": 10000,
        "amount": 1.0e-5,
        "from": "SENDER_ADDRESS_HERE"
    }
}
```

{% endtab %}
{% endtabs %}

### Example Verification URL

```
https://solpay.solblaze.org/transaction.php?to=RECIPIENT_ADDRESS&txid=TRANSACTION_SIGNATURE
```

## Example

### Frontend

{% tabs %}
{% tab title="index.html" %}

```html
<script src="https://solpay.solblaze.org/sdk.js" type="text/javascript"></script>
<script src="/index.js" type="text/javascript"></script>
<button onclick="connectWallet();">Connect</button>
<button onclick="buyItem();">Buy Item for 0.00001 SOL</button>
```

{% endtab %}

{% tab title="index.js" %}

```javascript
async function connectWallet() {
    /* Connect to Solana network: */
    let network_url = await SOLPay.connectNetwork();
    console.log(network_url); // "https://solana-api.projectserum.com"
    
    /* Connect to user wallet: */
    let wallet = await SOLPay.connectWallet();
    console.log(wallet.address); // the address of the connected wallet
}

async function buyItem() {
    let address = "SELLER_ADDRESS_HERE" // replace with the Solana address of the seller
    let lamports = 10000;
    let payment_details = await SOLPay.sendSolanaLamports(address, lamports);
    // IMPORTANT: Send payment_details.signature to the backend for verification
    let raw_result = await fetch("/verify.php?txid=" + encodeURIComponent(payment_details.signature));
    let parsed_result = await raw_result.json();
    // Use parsed_result to either return success message or error message to user
}
```

{% endtab %}
{% endtabs %}

### Backend

{% tabs %}
{% tab title="verify.php" %}

```php
// If the transaction signature is not yet in the database
$to = "SELLER_ADDRESS_HERE";
$txid = $_GET["txid"]; // Get the txid in the URL from frontend request
$transaction_data = json_decode(file_get_contents("https://solpay.solblaze.org/transaction.php?to=" . $to . "&txid=" . $txid), true);
if($transaction_data["status"] == "success" && $transaction_data["transaction"]["lamports"] >= 10000) {
    // Add the transaction signature to the database so that it cannot be reused
    // Send the item to the user associated with $transaction_data["transaction"]["from"]
} else if($transaction_data["status"] == "error") {
    // Send $transaction_data["error"] to the frontend to display to the user
} else {
    // Send an error to the user that not enough funds were sent in the transaction
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}

#### Important:

The above example is for reference only and lacks a few features recommended for more robust apps, including a preconfirm handler ([sendSolanaLamports](/reference/sdk-reference/send-solana-lamports)) and, if the app immediately returns the purchased item back to the client directly, a user signature ([signMessage](/reference/sdk-reference/sign-message)).
{% endhint %}


# Streams

Learn about how you can integrate SOL Pay Streams into your applications!

## Introduction

SOL Pay Streams are an innovative, fully non-custodial feature that allows micropayments to be accumulated every second and sent automatically from a user's Stream Wallet once a threshold is reached without requiring a user to constantly interact with their wallet (other than to refill the Stream Wallet whenever the balance is not healthy and is not enough for a transfer of the threshold amount). The Stream Wallet is held non-custodially on the SOL Pay side of the application and is not directly accessible by the main application except through the SDK. All stream requests require user approval, and no lamports will be sent from the Stream Wallet to the receiving address until the threshold amount has been reached.

{% hint style="danger" %}
**Warning:**&#x20;

The SOL Pay Stream Wallet should not be considered as a permanent wallet. While the Stream Wallet can theoretically hold funds even after the main application has been closed, there is no guarantee that the Stream Wallet will be able to hold funds over a long period of time, especially across browser restarts or crashes. It is highly recommended that applications prompt users to back up their Stream Wallet using the [backupStreamWallet](/reference/sdk-reference/backup-stream-wallet) method and restore their Stream Wallet at [solpay.solblaze.org/stream-wallet](https://solpay.solblaze.org/stream-wallet).
{% endhint %}

## Start Streaming

You can start a stream easily in just a few lines of code (a single line of additional code after connecting to a user's wallet and the Solana network)! The below example streams 0.0000025 SOL per second and transfers at least 0.00015 SOL (the threshold amount) per minute from the pending stream balance to the receiving address. The Stream Wallet is refilled with 0.01 SOL whenever the balance is no longer healthy (not able to cover a transfer of the threshold amount).

Make sure to import the SOL Pay SDK using the instructions from the [Quick Start](/quick-start) page.

For more details about the code below, see the [streamLamports](/reference/sdk-reference/stream-lamports) method.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* Connect to wallet and network */
    await SOLPay.connectNetwork();
    await SOLPay.connectWallet();
    
    /* Start stream:                                   */
    /* 0.0000025 SOL accumulated per second            */
    /* 0.00015 SOL threshold to automatically transfer */
    /* 0.01 SOL refill when Stream Wallet runs low     */
    let stream = await SOLPay.streamLamports(
        "RECEIVING ADDRESS HERE",
        2500,
        10 ** 7,
        150000
    ); // true
})();
```

{% endtab %}
{% endtabs %}

## Back Up Wallet (HIGHLY RECOMMENDED)

It is highly recommended that you prompt users to create a backup of their Stream Wallet.

For more details about the code below, see the [backupStreamWallet](/reference/sdk-reference/backup-stream-wallet) method.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* ... */
    
    let backed_up = await SOLPay.backupStreamWallet(); // true
})();
```

{% endtab %}
{% endtabs %}

## Get Stream Details

At any point in time, you might want to know how much of the streamed lamports have been sent to the receiving wallet, how much is still pending (not yet at the threshold), the list of transaction signatures for stream transactions (which can be verified using [transaction.php](/reference/api-reference/transaction)), whether the balance of the stream is healthy, when the last refill was requested, whether the stream is paused, or whether the stream is closed.&#x20;

For more details about the code below, see the [getStreamDetails](/reference/sdk-reference/get-stream-details) method.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* ... */
    
    let details = await SOLPay.getStreamDetails(stream);
    /* {                           */
    /*     type: "...",            */
    /*     pending: 0,             */
    /*     sent: 0,                */
    /*     signatures: [...],      */
    /*     healthyBalance: true,   */
    /*     lastRequestedRefill: 0, */
    /*     paused: false           */
    /*     closed: false           */
    /* }                           */
})();
```

{% endtab %}
{% endtabs %}

## Refill Stream Wallet

The SOL Pay Stream Wallet is a non-custodial wallet held on the SOL Pay side of the application and is not accessible from the application directly. At some point, the Stream Wallet will run low on funds since all of the funds in the wallet have been streamed. Once the Stream Wallet no longer has a healthy balance (the threshold amount plus fees), SOL Pay will automatically start requesting a refill of the specified refill amount from the user every 45 seconds (starting immediately when the balance is no longer healthy).

However, if you want to override this 45 second delay in the case where a user accidentally declines the refill request (this override should be in the form of a manual button), there is a refill method available. The refill method will only request a refill if the balance is no longer healthy.

For more details about the code below, see the [refillStream](/reference/sdk-reference/refill-stream) method.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* ... */
    
    let refillRequested = await SOLPay.refillStream(stream); // true
})();
```

{% endtab %}
{% endtabs %}

## Pause and Resume Stream

If you want to pause or resume the stream, you can use the pause and resume stream methods. If a stream is paused, any pending lamports will still be transferred if the amount of pending lamports is greater than the threshold. If the amount of pending lamports is below the threshold, no lamports will be transferred. However, if the balance of the Stream Wallet is not healthy, the user will still be prompted to refill the Stream Wallet. To disable these prompts and forfeit the pending lamports, please see the next section.

For more details about the code below, see the [pauseStream](/reference/sdk-reference/pause-stream) and [resumeStream](/reference/sdk-reference/resume-stream) methods.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* ... */
    
    let paused = await SOLPay.pauseStream(stream); // true
    
    let resumed = await SOLPay.resumeStream(stream); // true
})();
```

{% endtab %}
{% endtabs %}

## Close Stream

Once you want to close the stream, you can use the close stream method. Closing the stream will cancel all pending transfers, even if the amount of pending lamports is greater than the threshold. If you want to stop the stream but still want to recover any pending lamports in cases where the amount of pending lamports is greater than the threshold, please use the pause stream method instead.

There is no way to immediately recover pending lamports if the pending amount is less than the threshold. Instead, you can optionally retrieve the pending lamports using the [getStreamDetails](/reference/sdk-reference/get-stream-details) method and send them using one of the SOL Pay transaction methods (you may not always want to retrieve the pending lamports if the fee is too large compared to the pending amount).

The close stream method awaits for any pending transactions related to the current stream (refills or transfers) to complete to ensure that the state of the stream is finalized.

For more details about the code below, see the [closeStream](/reference/sdk-reference/close-stream) and [sendSolanaLamports](/reference/sdk-reference/send-solana-lamports) methods.

{% tabs %}
{% tab title="index.js" %}

```javascript
(async() => {
    /* ... */
    
    /* Close stream */
    let closed = await SOLPay.closeStream(stream); // true
    
    /* Retrieve final details (optional) */
    let finalDetails = await SOLPay.getStreamDetails(stream);
    
    /* Send the unsent pending stream balance manually (optional) */
    let transaction = await sendSolanaLamports(
        "RECEIVING ADDRESS HERE",
        finalDetails.pending
    );
    
    /* Calculate total amount streamed (optional) */
    let totalStreamed = finalDetails.sent + finalDetails.pending;
    console.log(`Streamed ${totalStreamed / (10 ** 9)} SOL in total!`);
})();
```

{% endtab %}
{% endtabs %}


# Stake Pools

Integrate stake pools into your application!

The quick start guide for stake pools is coming soon, stay tuned!


# SDK Reference

Dive into the specifics of each SDK method by checking out our complete documentation.

## connectNetwork

Connecting to the Solana network:

{% content-ref url="/pages/d4p0EHH04o2sn8XdyjUR" %}
[connectNetwork](/reference/sdk-reference/connect-network)
{% endcontent-ref %}

## connectWallet

Connecting to the user's wallet:

{% content-ref url="/pages/nNOzUMOzm9uho09fkFZ1" %}
[connectWallet](/reference/sdk-reference/connect-wallet)
{% endcontent-ref %}

## sendSolanaLamports

Sending Solana lamports (recommended):

{% content-ref url="/pages/v8BU1D7B7pmsezBpBDy8" %}
[sendSolanaLamports](/reference/sdk-reference/send-solana-lamports)
{% endcontent-ref %}

## sendSolana

Sending Solana (not recommended):

{% content-ref url="/pages/EpCPHFaVV6qQGvFZyWoE" %}
[sendSolana](/reference/sdk-reference/send-solana)
{% endcontent-ref %}

## sendTokens

Sending an SPL token in terms of it's lowest denomination (recommended):

{% content-ref url="/pages/3bwXc9FPPHtlQjuV1ZxG" %}
[sendTokens](/reference/sdk-reference/send-tokens)
{% endcontent-ref %}

## sendTokensDecimal

Sending an SPL token in a decimal amount (not recommended):

{% content-ref url="/pages/KbmJ7i50xY9HkmiVecz3" %}
[sendTokensDecimal](/reference/sdk-reference/send-tokens-decimal)
{% endcontent-ref %}

## signTransaction

Signing a transaction with multiple instructions:

{% content-ref url="/pages/rJWbhZZww2vzDa1TIoDM" %}
[signTransaction](/reference/sdk-reference/sign-transaction)
{% endcontent-ref %}

## broadcastSerializedTransaction

Broadcasting the serialized transaction from `signTransaction` to be confirmed on the Solana network:

{% content-ref url="/pages/mBBSe4bg1GthVrfF2QJR" %}
[broadcastSerializedTransaction](/reference/sdk-reference/broadcast-serialized-transaction)
{% endcontent-ref %}

## signMessage

Signing a message using the user's private key:

{% content-ref url="/pages/fulOWzps9RvzlJy6EH6H" %}
[signMessage](/reference/sdk-reference/sign-message)
{% endcontent-ref %}

## getBalance

Getting the Solana lamports balance of an account:

{% content-ref url="/pages/t1QyzimyTXQSXEopCX9G" %}
[getBalance](/reference/sdk-reference/get-balance)
{% endcontent-ref %}

## getTokenBalances

Getting all of the token balances held by a Solana account:

{% content-ref url="/pages/quahjYU9HFgEv6m67B5K" %}
[getTokenBalances](/reference/sdk-reference/get-token-balances)
{% endcontent-ref %}

## getAccountInfo

Getting the info for an account:

{% content-ref url="/pages/y1FerhD3Vvq7DdkWsgtL" %}
[getAccountInfo](/reference/sdk-reference/get-account-info)
{% endcontent-ref %}

## getAssociatedTokenAddress

Getting the associated token address of an account:

{% content-ref url="/pages/PWYXYgYwoLVfPnj4ALPM" %}
[getAssociatedTokenAddress](/reference/sdk-reference/get-associated-token-address)
{% endcontent-ref %}

## getTokenBalance

Getting the balance for a token held by a Solana account:

{% content-ref url="/pages/rJcnOusSQB9qPLhvWo6q" %}
[getTokenBalance](/reference/sdk-reference/get-token-balance)
{% endcontent-ref %}

## tokens.getData

Getting the raw data of a token:

{% content-ref url="/pages/8RCuavIy3QmRjJ95JTTG" %}
[tokens.getData](/reference/sdk-reference/tokens-get-data)
{% endcontent-ref %}

## tokens.getTags

Getting a list of SPL token registry tags and their descriptions:

{% content-ref url="/pages/YIQgR491YUcLSQROyPis" %}
[tokens.getTags](/reference/sdk-reference/tokens-get-tags)
{% endcontent-ref %}

## tokens.getToken

Getting the SPL token metadata from the SPL token registry:

{% content-ref url="/pages/yfEpRbDqaiOWqYdEIkk4" %}
[tokens.getToken](/reference/sdk-reference/tokens-get-token)
{% endcontent-ref %}

## tokens.search

Searching for an SPL token in the SPL token registry:

{% content-ref url="/pages/LPjpgu9ViYZPty72mkgQ" %}
[tokens.search](/reference/sdk-reference/tokens-search)
{% endcontent-ref %}

## tokens.getRawUnvalidatedList

Getting the raw, unvalidated list of tokens in the SPL token registry:

{% content-ref url="/pages/I1JMCbuxrsSPg6lbhJmY" %}
[tokens.getRawUnvalidatedList](/reference/sdk-reference/tokens-get-raw-unvalidated-list)
{% endcontent-ref %}

## adapters

Using adapters to connect to a wallet:

{% content-ref url="/pages/IiF6VLRSe1XEQWdIy9Lu" %}
[adapters](/reference/sdk-reference/adapters)
{% endcontent-ref %}


# connectNetwork

Connects to the Solana network through an RPC endpoint

```javascript
(async() => {
    await SOLPay.connectNetwork("https://solana-api.projectserum.com", "confirmed"); // {"network": "https://solana-api.projectserum.com", "commitment": "confirmed"}
    await SOLPay.connectNetwork(); // {"network": "...", "commitment": "confirmed"}
})();
```

### Parameters:

* network (optional, default: default RPC network): string - the RPC URL to use for the connection
* commitment (optional, default: `"confirmed"`): string - the commitment to use for the connection

{% hint style="info" %}
**Networks:**

For more information on networks, see [networks](/reference/sdk-reference/networks).
{% endhint %}

### Returns:

object (`{"network": "...", "commitment": "..."}`) - the connection details

* network: string (`"`[`https://solana-api.projectserum.com`](https://solana-api.projectserum.com)`"`) - the RPC URL used for the connection
* commitment: string (`"confirmed"`) - the commitment used for the connection

### Throws:

* `SOL Pay SDK Fatal Error: Invalid network ${network}.` - network not specified or unable to connect to the network


# connectWallet

Connects to a Solana Web3 wallet:

```javascript
(async() => {
    await SOLPay.connectWallet(); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.PHANTOM); // {"address": "..."}
})();
```

### Parameters:

* adapter (optional, default: `SOLPay.adapters.CURRENT_ADAPTER || SOLPay.adapters.PHANTOM`) - the wallet to use for the connection
  * Current Adapter: `SOLPay.adapters.CURRENT_ADAPTER` (or leave the adapter field blank)
  * Phantom: `SOLPay.adapters.PHANTOM`
  * Solflare: `SOLPay.adapters.SOLFLARE`
  * Slope: `SOLPay.adapters.SLOPE`
  * Glow: `SOLPay.adapters.GLOW`
  * Exodus: `SOLPay.adapters.EXODUS`
  * Brave: `SOLPay.adapters.BRAVE`

{% hint style="info" %}
**Adapters:**

For more information on adapters, see [adapters](/reference/sdk-reference/adapters).
{% endhint %}

### Returns:

object (`{"address": "..."}`) - the wallet details for the connected wallet

* address: string (`"..."`) - the address of the wallet

### Throws:

* `SOL Pay SDK Fatal Error: Invalid adapter ${adapter}.` - an invalid adapter was used
* `SOL Pay SDK Fatal Error: No adapter found.` - could not find an adapter
* `SOL Pay SDK Fatal Error: Solana wallet not found!` - could not find the wallet installed in the user's browser
* `SOL Pay SDK Fatal Error: Could not connect to Solana wallet!` - could not connect to the wallet

### Side Effects:

* SOL Pay will attempt to open the wallet's official website in a new window if it cannot find the wallet installed in the browser (`SOL Pay SDK Fatal Error: Solana wallet not found!`).
  * Phantom: [phantom.app](https://phantom.app/)
  * Solflare: [solflare.com](https://solflare.com/)
  * Slope: [slope.finance](https://slope.finance/)
  * Glow: [glow.app](https://glow.app/)
  * Exodus: [www.exodus.com/browser-extension](https://www.exodus.com/browser-extension/)
  * Brave: [brave.com/wallet](https://brave.com/wallet)


# sendSolanaLamports

Sends Solana Lamports from the user's wallet and awaits network confirmation

```javascript
(async() => {
    await SOLPay.sendSolanaLamports("WALLET_ADDRESS", 1); // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 1, "signature": "..."}
    await SOLPay.sendSolanaLamports("WALLET_ADDRESS", 1, (details) => {
        // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 1, "signature": "..."}
    }); // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 1, "signature": "..."}
})();
```

### Parameters:

* address: string - the address where the funds should be sent
* lamports: number - the number of lamports to send (one billion lamports are in 1 SOL)
* preconfirm (optional, default: `(details) => {}`): function - a function to capture the unconfirmed and unbroadcasted transaction details before the transaction has been broadcasted and confirmed on the Solana network

### Returns:

object (`{"from": "...", "to": "WALLET_ADDRESS", "lamports": 1, "signature": "..."}`) - the transaction details

* from: string (`"..."`) - the address from which Solana is sent
* to: string (`"..."`) - the address to which Solana is sent
* lamports: number (`1`) - the number of lamports sent
* signature: string (`"..."`) - the signature of the transaction

### Throws:

* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Unable to get recent blockhash.` - was not able to get a recent blockhash
* `SOL Pay SDK Fatal Error: SOL Pay SDK Fatal Error: Unable to broadcast transaction.` - was not able to broadcast the transaction
* `SOL Pay SDK Fatal Error: The preconfirm function returned an error, halting the transaction from being sent: ${err}` - did not send transaction because the preconfirm function could not be run to completion successfully
* `SOL Pay SDK Fatal Error: Invalid transfers ${transfers}.` - invalid transfers were used
* `SOL Pay SDK Fatal Error: Invalid serialized transaction ${serialized_transaction}.` - an invalid serialized transaction was used

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL.
{% endhint %}


# sendSolana

Sends Solana from the user's wallet and awaits network confirmation

{% hint style="warning" %}

#### Important:

This method may lead to slightly inaccurate results due to decimal roundoff error. We highly recommend using the sendSolanaLamports method ([sendSolanaLamports](/reference/sdk-reference/send-solana-lamports)) instead.
{% endhint %}

Sends Solana from the user's wallet and awaits network confirmation

```javascript
(async() => {
    await SOLPay.sendSolana("WALLET_ADDRESS", 0.00001); // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 10000, "signature": "..."}
    await SOLPay.sendSolana("WALLET_ADDRESS", 0.00001, (details) => {
        // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 10000, "signature": "..."}
    }); // {"from": "...", "to": "WALLET_ADDRESS", "lamports": 10000, "signature": "..."}
})();
```

### Parameters:

* address: string - the address where the funds should be sent
* amount: number - the amount of Solana to send
* preconfirm (optional, default: `(details) => {}`): function - a function to capture the unconfirmed and unbroadcasted transaction details before the transaction has been broadcasted and confirmed on the Solana network

### Returns:

object (`{"from": "...", "to": "WALLET_ADDRESS", "lamports": 1, "signature": "..."}`) - the transaction details

* from: string (`"..."`) - the address from which Solana is sent
* to: string (`"..."`) - the address to which Solana is sent
* lamports: number (`1`) - the number of lamports sent
* signature: string (`"..."`) - the signature of the transaction

### Throws:

* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Unable to get recent blockhash.` - was not able to get a recent blockhash
* `SOL Pay SDK Fatal Error: SOL Pay SDK Fatal Error: Unable to broadcast transaction.` - was not able to broadcast the transaction
* `SOL Pay SDK Fatal Error: The preconfirm function returned an error, halting the transaction from being sent: ${err}` - did not send transaction because the preconfirm function could not be run to completion successfully
* `SOL Pay SDK Fatal Error: Invalid transfers ${transfers}.` - invalid transfers were used
* `SOL Pay SDK Fatal Error: Invalid serialized transaction ${serialized_transaction}.` - an invalid serialized transaction was used

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL.
{% endhint %}


# sendTokens

Sends SPL tokens from the user's wallet and awaits network confirmation

```javascript
(async() => {
    await SOLPay.sendTokens("RECIPIENT_ADDRESS", 1, "TOKEN_ADDRESS"); // {"from": "...", "to": "WALLET_ADDRESS", "amount": 1, "token_address": "TOKEN_ADDRESS", "signature": "..."}
    await SOLPay.sendTokens("RECIPIENT_ADDRESS", 1, "TOKEN_ADDRESS", (details) => {
        // {"from": "...", "to": "WALLET_ADDRESS", "amount": 1, "token_address": "TOKEN_ADDRESS", "signature": "..."}
    }); // {"from": "...", "to": "WALLET_ADDRESS", "amount": 1, "token_address": "TOKEN_ADDRESS", "signature": "..."}
})();
```

### Parameters:

* address: string - the address where the tokens should be sent
* amount: number - the amount of tokens to send with the smallest denomination of tokens being represented by amount 1
* token\_address: string - the mint address of the token
* preconfirm (optional, default: `(details) => {}`): function - a function to capture the unconfirmed and unbroadcasted transaction details before the transaction has been broadcasted and confirmed on the Solana network

### Returns:

object (`{"from": "...", "to": "WALLET_ADDRESS", "amount": 1, "token_address": "TOKEN_ADDRESS", "signature": "..."}`) - the transaction details

* from: string (`"..."`) - the address from which Solana is sent
* to: string (`"..."`) - the address to which Solana is sent
* amount: number (`1`) - the number of tokens sent (in terms of the token's base unit)
* token\_address: string(`"..."`) - the address of the token sent
* signature: string (`"..."`) - the signature of the transaction

### Throws:

* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Unable to get recent blockhash.` - was not able to get a recent blockhash
* `SOL Pay SDK Fatal Error: SOL Pay SDK Fatal Error: Unable to broadcast transaction.` - was not able to broadcast the transaction
* `SOL Pay SDK Fatal Error: The preconfirm function returned an error, halting the transaction from being sent: ${err}` - did not send transaction because the preconfirm function could not be run to completion successfully
* `SOL Pay SDK Fatal Error: Invalid transfers ${transfers}.` - invalid transfers were used
* `SOL Pay SDK Fatal Error: Invalid serialized transaction ${serialized_transaction}.` - an invalid serialized transaction was used

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL.
{% endhint %}


# sendTokensDecimal

Sends SPL tokens from the user's wallet and awaits network confirmation

{% hint style="warning" %}

#### Important:

This method may lead to slightly inaccurate results due to decimal roundoff error. We highly recommend using the sendTokens method ([sendTokens](/reference/sdk-reference/send-tokens)) instead.
{% endhint %}

```javascript
(async() => {
    await SOLPay.sendTokensDecimal("WALLET_ADDRESS", 0.00001, "TOKEN_ADDRESS"); // {"from": "...", "to": "WALLET_ADDRESS", "amount_decimal": 0.00001, "token_address": "TOKEN_ADDRESS", "signature": "..."}
    await SOLPay.sendTokensDecimal("WALLET_ADDRESS", 0.00001, "TOKEN_ADDRESS", (details) => {
        // {"from": "...", "to": "WALLET_ADDRESS", "amount_decimal": 0.00001, "token_address": "TOKEN_ADDRESS", "signature": "..."}
    }); // {"from": "...", "to": "WALLET_ADDRESS", "amount_decimal": 0.00001, "token_address": "TOKEN_ADDRESS", "signature": "..."}
})();
```

### Parameters:

* address: string - the address where the tokens should be sent
* amount\_decimal: number - the decimal amount of tokens to send
* token\_address: string - the mint address of the token
* preconfirm (optional, default: `(details) => {}`): function - a function to capture the unconfirmed and unbroadcasted transaction details before the transaction has been broadcasted and confirmed on the Solana network

### Returns:

object (`{"from": "...", "to": "WALLET_ADDRESS", "amount_decimal": 0.00001, "token_address": "TOKEN_ADDRESS", "signature": "..."}`) - the transaction details

* from: string (`"..."`) - the address from which Solana is sent
* to: string (`"..."`) - the address to which Solana is sent
* amount\_decimal: number (`0.00001`) - the amount of tokens sent
* token\_address: string(`"..."`) - the address of the token sent
* signature: string (`"..."`) - the signature of the transaction

### Throws:

* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Unable to get recent blockhash.` - was not able to get a recent blockhash
* `SOL Pay SDK Fatal Error: SOL Pay SDK Fatal Error: Unable to broadcast transaction.` - was not able to broadcast the transaction
* `SOL Pay SDK Fatal Error: The preconfirm function returned an error, halting the transaction from being sent: ${err}` - did not send transaction because the preconfirm function could not be run to completion successfully
* `SOL Pay SDK Fatal Error: Invalid transfers ${transfers}.` - invalid transfers were used
* `SOL Pay SDK Fatal Error: Invalid serialized transaction ${serialized_transaction}.` - an invalid serialized transaction was used

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL.
{% endhint %}


# signTransaction

Signs a transaction with multiple instructions using the user's private key so that it can be separately broadcast to the network

```javascript
(async() => {
    let signed_tx = await SOLPay.signTransaction([{
        type: "solana_transfer",
        data: {
            address: "RECIPIENT_ADDRESS",
            lamports: 1
        }
    }, {
        type: "spl_token_transfer",
        data: {
            token_address: "TOKEN_ADDRESS",
            address: "RECIPIENT_ADDRESS",
            amount: 1
        }
    }, {
        type: "spl_token_transfer",
        data: {
            token_address: "TOKEN_ADDRESS",
            address: "RECIPIENT_ADDRESS",
            amount_decimal: 0.00001
        }
    }]); // {"from": "...", "transfers": [...], "signature": "...", "serialized_transaction": Uint8Array [...]}
})();
```

### Parameters:

* transfers: Array - the list of transfers to sign
  * type: string - the type of transfer to make (`solana_transfer` for a Solana transfer, `spl_token_transfer` for an SPL token transfer)
  * data: object - the transfer details
    * address: string - the address where the funds should be sent
    * \[`solana_transfer`] lamports: number - the number of lamports to send (one billion lamports are in 1 SOL)
    * \[`spl_token_transfer`] token\_address: string - the mint address of the token
    * EITHER amount: number - the amount of tokens to send with the smallest denomination of tokens being represented by amount 1 (recommended)
    * OR amount\_decimal: number - the decimal amount of tokens to send (not recommended)

### Returns:

object (`{"from": "...", "transfers": [...], "signature": "...", "serialized_transaction": Uint8Array [...]}`) - the transaction details

* from: string (`"..."`) - the address from which Solana is sent
* transfers: Array (`[...]`) - the transfers of the transaction
* signature: string (`"..."`) - the signature of the transaction
* serialized\_transaction: Uint8Array (`Uint8Array [...]`) - the serialized transaction (which can be broadcasted to the network)

### Throws:

* `SOL Pay SDK Fatal Error: Invalid transfers ${transfers}.` - invalid transfers were used
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Unable to get recent blockhash.` - was not able to get a recent blockhash

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL.
{% endhint %}


# broadcastSerializedTransaction

Broadcasts a serialized, signed transaction to be confirmed on the Solana network

```javascript
(async() => {
    let broadcasted_tx = await SOLPay.broadcastSerializedTransaction([...]); // {"signature": "..."}
})();
```

### Parameters:

* serialized\_transaction: Uint8Array - the serialized, signed transaction to broadcast, which can be obtained through the `signTransaction` method ([signTransaction](/reference/sdk-reference/sign-transaction))

### Returns:

object (`{"signature": "..."}`) - the transaction details

* signature: string (`"..."`) - the signature of the transaction

### Throws:

* `SOL Pay SDK Fatal Error: Invalid serialized transaction ${serialized_transaction}.` - an invalid serialized transaction was used
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: SOL Pay SDK Fatal Error: Unable to broadcast transaction.` - was not able to broadcast the transaction


# streamLamports

Streams lamports to a receiving address

{% hint style="danger" %}
**Warning:**&#x20;

The SOL Pay Stream Wallet should not be considered as a permanent wallet. While the Stream Wallet can theoretically hold funds even after the main application has been closed, there is no guarantee that the Stream Wallet will be able to hold funds over a long period of time, especially across browser restarts or crashes. It is highly recommended that applications prompt users to back up their Stream Wallet using the [backupStreamWallet](/reference/sdk-reference/backup-stream-wallet) method and restore their Stream Wallet at [solpay.solblaze.org/stream-wallet](https://solpay.solblaze.org/stream-wallet).
{% endhint %}

{% hint style="info" %}
**Note:**

SOL Pay Streams are an innovative, fully non-custodial feature that allows micropayments to be accumulated every second and sent automatically from a user's Stream Wallet once a threshold is reached without requiring a user to constantly interact with their wallet (other than to refill the Stream Wallet whenever the balance is not healthy and is not enough for a transfer of the threshold amount). The Stream Wallet is held non-custodially on the SOL Pay side of the application and is not directly accessible by the main application except through the SDK. All stream requests require user approval, and no lamports will be sent from the Stream Wallet to the receiving address until the threshold amount has been reached.

The below example streams 0.0000025 SOL per second and transfers at least 0.00015 SOL (the threshold amount) per minute from the pending stream balance to the receiving address. The Stream Wallet is refilled with 0.01 SOL whenever the balance is no longer healthy (not able to cover a transfer of the threshold amount).
{% endhint %}

```javascript
(async() => {
    let stream = await SOLPay.streamLamports("...", 2500, 10 ** 7, 150000); // true
})();
```

### Parameters:

* address: string - the address to send the streamed lamports
* lamportsPerSecond: number - the number of lamports to stream per second (accumulates in a pending balance)
* refillLamports (optional, default: `10000000`): number - the number of lamports to request for refills to the Stream Wallet
* thresholdLamports (optional, default: `100000`): number - the minimum number of lamports required to transfer the pending lamports to the receiving address

### Returns:

string (`...`) - the stream identifier (which can be used in the other stream methods)

### Throws:

* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: No wallet connection found. Use SOLPay.connectWallet() to connect to a Solana wallet.` - no wallet was connected
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network
* `Uncaught SOL Pay SDK Fatal Error: User rejected the stream request.` - did not receive approval from the user to start the stream
* `SOL Pay SDK Fatal Error: Invalid address ${address}.` - an invalid address was used
* `SOL Pay SDK Fatal Error: Invalid lamports per second ${lamportsPerSecond}.` - an invalid lamports per second value was used
* `SOL Pay SDK Fatal Error: Invalid refill lamports ${refillLamports}.` - an invalid refill lamports value was used
* `SOL Pay SDK Fatal Error: Invalid threshold lamports ${thresholdLamports}.` - an invalid threshold lamports value was used

{% hint style="info" %}
**Note:**

Sending a transaction includes a fee of at least 0.000005 SOL. This fee is charged every time the pending amount of lamports reaches the threshold and comes out of the Stream Wallet. The fee is not deducted from the transferred amount.
{% endhint %}


# backupStreamWallet

Prompts the user to create a backup of their Stream Wallet

{% hint style="info" %}
**Note:**

The Stream Wallet backup process involves a popup window that opens a SOL Pay webpage. Users may need to know how to allow popups, although the backup generation prompt will include some basic instructions.
{% endhint %}

```javascript
(async() => {
    let backed_up = await SOLPay.backupStreamWallet(); // true
})();
```

### Returns:

boolean (`true`) - whether a backup was generated


# getStreamDetails

Gets the details of a stream

```javascript
(async() => {
    let details = await SOLPay.getStreamDetails("..."); // { type: "...", pending: 0, sent: 0, signatures: [...], healthyBalance: true, lastRequestedRefill: 0, paused: false, closed: false }
})();
```

### Parameters:

* stream: string - the stream for getting details

### Returns:

object (`{ type: "...", pending: 0, sent: 0, signatures: [...], healthyBalance: true, lastRequestedRefill: 0, paused: false, closed: false }`) - the stream details

* type: string (`"..."`) - the type of stream (`lamports`)
* pending: number (`0`) - the number of pending lamports that have not yet been transferred and are still accumulating in the Stream Wallet
* sent: number (`0`) - the number of lamports that have been transferred from the Stream Wallet to the receiving wallet
* signatures: Array (`[...]`) - the list of transaction signatures for transfers of lamports from the Stream Wallet to the receiving wallet (which can be verified using [transaction.php](/reference/api-reference/transaction))
* healthyBalance: boolean (`true`) - whether the balance of the Stream Wallet is healthy (enough to send one transfer at the threshold amount)
* lastRequestedRefill: number (`0`) - the timestamp (Unix timestamp in milliseconds) when the last refill was requested, this will be set to `0` if no refills have been requested or immediately after a refill is requested manually through the [refillStream](/reference/sdk-reference/refill-stream) method (but not when the refill is automatically requested on a 45 second interval when the balance is no longer healthy)
* paused: boolean (`false`) - whether the stream is paused
* closed: boolean (`false`) - whether the stream is closed

### Throws:

* `SOL Pay SDK Fatal Error: Invalid stream ${stream}.` - an invalid stream was used


# refillStream

Requests that a stream be refilled if the Stream Wallet balance is not healthy

{% hint style="info" %}
**Note:**

The stream will not be refilled if the balance of the Stream Wallet is healthy. Once the Stream Wallet balance is no longer healthy, a refill request is automatically sent every 45 seconds, so this method should only be used to override the 45 second delay.
{% endhint %}

```javascript
(async() => {
    let refillRequested = await SOLPay.refillStream("..."); // true
})();
```

### Parameters:

* stream: string - the stream for requesting a refill

### Returns:

boolean (`true`) - the confirmation for requesting a refill for a stream

### Throws:

* `SOL Pay SDK Fatal Error: Invalid stream ${stream}.` - an invalid stream was used


# pauseStream

Pauses an active stream

{% hint style="warning" %}
**Important:**

If a stream is paused, any pending lamports will still be transferred if the amount of pending lamports is greater than the threshold. If the amount of pending lamports is below the threshold, no lamports will be transferred. However, if the balance of the Stream Wallet is not healthy, the user will still be prompted to refill the Stream Wallet. To disable these prompts and forfeit the pending lamports, please use the [closeStream](/reference/sdk-reference/close-stream) method instead.
{% endhint %}

```javascript
(async() => {
    let paused = await SOLPay.pauseStream("..."); // true
})();
```

### Parameters:

* stream: string - the stream to pause

### Returns:

boolean (`true`) - the confirmation for pausing a stream

### Throws:

* `SOL Pay SDK Fatal Error: Invalid stream ${stream}.` - an invalid stream was used


# resumeStream

Resumes a paused stream

```javascript
(async() => {
    let resumed = await SOLPay.resumeStream("..."); // true
})();
```

### Parameters:

* stream: string - the stream to resume

### Returns:

boolean (`true`) - the confirmation for resuming a stream

### Throws:

* `SOL Pay SDK Fatal Error: Invalid stream ${stream}.` - an invalid stream was used


# closeStream

Closes an active stream

{% hint style="warning" %}
**Important:**

Closing the stream will cancel all pending transfers, sometimes even if the amount of pending lamports is greater than the threshold. If you want to stop the stream but still want to recover any pending lamports in cases where the amount of pending lamports is greater than the threshold, please use the [pauseStream](/reference/sdk-reference/pause-stream) method instead.

There is no way to immediately recover pending lamports if the pending amount is less than the threshold. Instead, you can optionally retrieve the pending lamports using the [getStreamDetails](/reference/sdk-reference/get-stream-details) method and send them using one of the SOL Pay transaction methods (you may not always want to retrieve the pending lamports if the fee is too large compared to the pending amount).

The close stream method awaits for any pending transactions related to the current stream (refills or transfers) to complete to ensure that the state of the stream is finalized.
{% endhint %}

```javascript
(async() => {
    let closed = await SOLPay.closeStream("..."); // true
})();
```

### Parameters:

* stream: string - the stream to close

### Returns:

boolean (`true`) - the confirmation for closing a stream

### Throws:

* `SOL Pay SDK Fatal Error: Invalid stream ${stream}.` - an invalid stream was used


# signMessage

Signs a message using the user's wallet

```javascript
(async() => {
    let signature = await SOLPay.signMessage("..."); // {"signature": "..."}
})();
```

### Parameters:

* message: string - the message to sign with the user's wallet

### Returns:

object (`{"signature": "..."}`) - the signature details

* signature: string (`"..."`) - the signature of the message

### Throws:

* `SOL Pay SDK Fatal Error: Invalid message ${message}.` - an invalid message was used


# getBalance

Gets the Solana lamports balance of an account

```javascript
(async() => {
    let balance_1 = await SOLPay.getBalance(); // {"lamports": 1}
    let balance_2 = await SOLPay.getBalance("SOLANA_ADDRESS"); // {"lamports": 1}
})();
```

### Parameters:

* address (optional, default: connected wallet address): string - the Solana address with which to get the Solana lamports balance

### Returns:

object (`{"lamports": 1}`) - the balance details for the specified address

* lamports: number (`1`) - the number of lamports in the account

### Throws:

* `SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet.` - an invalid address was used, and no wallet was connected
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# getTokenBalances

Gets the token balances of an account

```javascript
(async() => {
    let token_balances_1 = await SOLPay.getTokenBalances(); // {"balances": [...]}
    let token_balances_2 = await SOLPay.getTokenBalances("SOLANA_ADDRESS"); // {"balances": [...]}
})();
```

### Parameters:

* address (optional, default: connected wallet address): string - the Solana address with which to get the token balances

### Returns:

object (`{"balances": [...]}`) - the token balances data

* balances: Array (`[{...}, {...}, ...]`) - the list of balances
  * object (`{...}`) - the balances data of the account
    * raw\_data: object (`{...}`) - the raw data of the account
    * account: object (`{...}`) - the balance details of the account
      * address: string (`"..."`) - the address of the account
      * lamports: number (`10000`) - the number of lamports in the account
    * delegate: object (`{...}`) - the balance details of the delegate account
      * address: string (`"..."`) - the address of the delegate account
      * balance: object (`{...}`) - the token balance
        * amount: string (`"11"`) - the number of tokens as an integer
        * decimals: number (`9`) - the number digits after the decimal point in a token
        * uiAmount: number (`0.000000011`) - the number of tokens as a decimal (deprecated)
        * uiAmountString: string (`"0.000000011"`) - the number of tokens as a decimal in a string form
    * token: object (`{...}`) - the token balance details
      * address: string (`"..."`) - the address of the token
      * balance: object (`{...}`) - the token balance
        * amount: string (`"11"`) - the number of tokens as an integer
        * decimals: number (`9`) - the number digits after the decimal point in a token
        * uiAmount: number (`0.000000011`) - the number of tokens as a decimal (deprecated)
        * uiAmountString: string (`"0.000000011"`) - the number of tokens as a decimal in a string form

### Throws:

* `SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet.` - an invalid address was used, and no wallet was connected
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# getAccountInfo

Gets the info of an account

```javascript
(async() => {
    let account_info_1 = await SOLPay.getAccountInfo(); // {...}
    let account_info_2 = await SOLPay.getAccountInfo("ACCOUNT_ADDRESS"); // {...}
})();
```

### Parameters:

* address (optional, default: connected wallet address): string - the account address with which to get the info

### Returns:

object (`{...}`) - the account info

* raw\_data: object (`{...}`) - the raw data of the account
* executable: boolean (`false`) - whether the account is executable
* lamports: number (`10000`) - the number of lamports in the account
* owner: string (`"..."`) - the owner of the account
* rentEpoch: number (`250`) - the rent epoch
* info (if `executable` is `false`): object (`{...}`) - the parsed data of the account
* program (if `executable` is `false`): string (`spl-token`) - the program of the account
* space (if `executable` is `false`): number (`150`) - the space of the account
* type (if `executable` is `false`): string (`"account"`) - the type of the account

### Throws:

* `SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet.` - an invalid address was used, and no wallet was connected
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# getAssociatedTokenAddress

Gets the associated token address of a Solana account

```javascript
(async() => {
    let associated_token_address_1 = await SOLPay.getAssociatedTokenAddress("TOKEN_ADDRESS"); // {"address": "..."}
    let associated_token_address_2 = await SOLPay.getAssociatedTokenAddress("TOKEN_ADDRESS", "SOLANA_ADDRESS"); // {"address": "..."}
})();
```

### Parameters:

* token\_address: string - the mint address of the token with which to get the associated address
* address (optional, default: connected wallet address): string - the Solana address with which to get the associated address

### Returns:

object (`{"address": "..."}`) - the details for the associated token account

* address: string - the address of the associated token account

### Throws:

* `SOL Pay SDK Fatal Error: Invalid token address ${token_address}.` - an invalid token address was used
* `SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet.` - an invalid address was used, and no wallet was connected
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# getTokenBalance

Gets the token balance of a Solana account

```javascript
(async() => {
    let token_balance_1 = await SOLPay.getTokenBalance("TOKEN_ADDRESS"); // {...}
    let token_balance_2 = await SOLPay.getTokenBalance("TOKEN_ADDRESS", "SOLANA_ADDRESS"); // {...}
})();
```

### Parameters:

* token\_address: string - the mint address of the token with which to get the token balance
* address (optional, default: connected wallet address): string - the Solana address with which to get the token balance

### Returns:

object (`{...}`) - the token balance

* raw\_data: object (`{...}`) - the raw data of the account
* account: object (`{...}`) - the balance details of the account
  * address: string (`"..."`) - the address of the account
  * lamports: number (`10000`) - the number of lamports in the account
* token: object (`{...}`) - the token balance details
  * balance: object (`{...}`) - the token balance
    * amount: string (`"11"`) - the number of tokens as an integer
    * decimals: number (`9`) - the number digits after the decimal point in a token
    * uiAmount: number (`0.000000011`) - the number of tokens as a decimal (deprecated)
    * uiAmountString: string (`"0.000000011"`) - the number of tokens as a decimal in a string form

### Throws:

* `SOL Pay SDK Fatal Error: Invalid token address ${token_address}.` - an invalid token address was used
* `SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet.` - an invalid address was used, and no wallet was connected
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# tokens.getData

Gets the raw on-chain data for a token

```javascript
(async() => {
    let token_data = await SOLPay.tokens.getData("TOKEN_ADDRESS"); // {...}
})();
```

### Parameters:

* address: string - the mint address of the token with which to get the data

### Returns:

object (`{...}`) - the raw token data

* data: Uint8Array (`Uint8Array [...]`) - the raw data from the blockchain
* executable: boolean (`false`) - whether the token's account is executable
* lamports: number (`10000`) - the number of lamports in the token's account
* owner: string (`"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"`) - the owner of the token's account
* rentEpoch: number (`250`) - the rent epoch

### Throws:

* `SOL Pay SDK Fatal Error: Invalid address ${address}.` - an invalid address was used
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# tokens.getTags

Gets the tags from the SPL token registry

```javascript
(async() => {
    let token_tags = await SOLPay.tokens.getTags(); // {"tags": {...}}
})();
```

### Returns:

object (`{"tags": {...}}`) - the token tags (see <https://github.com/solana-labs/token-list/blob/main/src/tokens/solana.tokenlist.json> for format)


# tokens.getToken

Gets the metadata for an SPL token from the SPL token registry

```javascript
(async() => {
    let token_info_1 = await SOLPay.tokens.getToken("TOKEN_ADDRESS"); // {...}
    let token_info_2 = await SOLPay.tokens.getToken("TOKEN_ADDRESS", true); // {...}
})();
```

### Parameters:

* address: string - the mint address of the token with which to get the info from the SPL token registry
* skip\_validation (optional, default: `false`): boolean - whether to skip validation on if a token in the SPL token registry is a valid SPL token (true for skipping validation, false for not skipping validation)

### Returns:

object (`{...}`) - the token information (see <https://github.com/solana-labs/token-list/blob/main/src/tokens/solana.tokenlist.json> for format)

### Throws:

* `SOL Pay SDK Fatal Error: Invalid address ${address}.` - an invalid address was used
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# tokens.search

Searches for an SPL token in the SPL token registry

```javascript
(async() => {
    let token_search_1 = await SOLPay.tokens.search("symbol", "USDC"); // {"tokens": [...]}
    let token_search_2 = await SOLPay.tokens.search("symbol", "USDC", "equals"); // {"tokens": [...]}
    let token_search_3 = await SOLPay.tokens.search("symbol", "USDC", "equals", true); // {"tokens": [...]}
})();
```

### Parameters:

* search: string - what to use to search (`address`, `name`, `symbol`)
* param: string - the parameter/search term to use to find a token
* compare\_type (optional, default: `"equals"`): string - how to compare the search for tokens (`equals`, `startsWith`, `endsWith`, `includes`)
* skip\_validation (optional, default: `false`): boolean - whether to skip validation on if a token in the SPL token registry is a valid SPL token (true for skipping validation, false for not skipping validation), it is recommended to set this field to true when a large number of tokens are being returned and you want the function to execute quickly

### Returns:

object (`{"tokens": [...]}`) - the list of tokens (see <https://github.com/solana-labs/token-list/blob/main/src/tokens/solana.tokenlist.json> for format)

### Throws:

* `SOL Pay SDK Fatal Error: Invalid search ${search}.` - an invalid search was used
* `SOL Pay SDK Fatal Error: Invalid compare type ${compare_type}.` - an invalid compare type was used
* `SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network.` - could not find a connection to the Solana network
* `SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network.` - did not receive response from Solana network


# tokens.getRawUnvalidatedList

Gets the raw, unvalidated list of tokens in the SPL token registry

```javascript
(async() => {
    let token_list = await SOLPay.tokens.getRawUnvalidatedList(); // {"tokens": [...]}
})();
```

### Returns:

object (`{"tokens": [...]}`) - the list of tokens (see <https://github.com/solana-labs/token-list/blob/main/src/tokens/solana.tokenlist.json> for format)


# adapters

Adapters that can be used to connect to the user's wallet

```javascript
(async() => {
    SOLPay.adapters.CURRENT_ADAPTER // Current wallet adapter
    SOLPay.adapters.PHANTOM // Phantom wallet adapter
    SOLPay.adapters.SOLFLARE // Solflare wallet adapter
    SOLPay.adapters.SLOPE // Slope wallet adapter
    SOLPay.adapters.GLOW // Glow wallet adapter
    SOLPay.adapters.EXODUS // Exodus wallet adapter

    await SOLPay.connectWallet(SOLPay.adapters.CURRENT_WALLET); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.PHANTOM); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.SOLFLARE); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.SLOPE); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.GLOW); // {"address": "..."}
    await SOLPay.connectWallet(SOLPay.adapters.EXODUS); // {"address": "..."}
})();
```

### Properties

* CURRENT\_ADAPTER - The adapter that is currently being used (leave the adapter field blank to use this adapter by default)
* PHANTOM - Phantom wallet adapter ([phantom.app](https://phantom.app/))
* SOLFLARE - Solflare wallet adapter ([solflare.com](https://solflare.com/))
* SLOPE - Slope wallet adapter ([slope.finance](https://slope.finance/))
* GLOW - Glow wallet adapter ([glow.app](https://glow.app/))
* EXODUS - Exodus wallet adapter ([exodus.com/browser-extension](https://www.exodus.com/browser-extension/))
* BRAVE - Brave wallet adapter ([brave.com/wallet](https://brave.com/wallet))


# networks

Networks that can be used to connect to the Solana network

```javascript
(async() => {
    SOLPay.networks.mainnet.SOLANA // Solana mainnet endpoint
    SOLPay.networks.mainnet.SERUM // Project Serum mainnet endpoint
    SOLPay.networks.mainnet.TRITON // Triton/RPC Pool mainnet endpoint
    SOLPay.networks.mainnet.PHANTOM // Phantom mainnet endpoint
    SOLPay.networks.mainnet.GENESYSGO // GenesysGo mainnet endpoint
    SOLPay.networks.mainnet.SOLANAPAY // Solana Pay/GenesysGo endpoint
    SOLPay.networks.devnet.SOLANA // Solana devnet endpoint
    SOLPay.networks.testnet.SOLANA // Solana testnet endpoint

    await SOLPay.connectNetwork(SOLPay.networks.mainnet.SOLANA); // {"network": "https://api.mainnet-beta.solana.com", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.mainnet.SERUM); // {"network": "https://solana-api.projectserum.com", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.mainnet.TRITON); // {"network": "https://free.rpcpool.com", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.mainnet.PHANTOM); // {"network": "https://solana-mainnet.phantom.tech", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.mainnet.GENESYSGO); // {"network": "https://ssc-dao.genesysgo.net", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.mainnet.SOLANAPAY); // {"network": "https://solanapay.genesysgo.net", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.devnet.SOLANA); // {"network": "https://api.devnet.solana.com", "commitment": "confirmed"}
    await SOLPay.connectNetwork(SOLPay.networks.testnet.SOLANA); // {"network": "https://api.testnet.solana.com", "commitment": "confirmed"}
})();
```

### Networks

* mainnet
  * SOLANA - Solana endpoint ([api.mainnet-beta.solana.com](https://api.mainnet-beta.solana.com))
  * SERUM - Project Serum endpoint ([solana-api.projectserum.com](https://solana-api.projectserum.com))
  * TRITON - Triton/RPC Pool endpoint ([free.rpcpool.com](https://free.rpcpool.com))
  * PHANTOM - Phantom endpoint ([solana-mainnet.phantom.tech](https://solana-mainnet.phantom.tech))
  * GENESYSGO - GenesysGo endpoint ([ssc-dao.genesysgo.net](https://ssc-dao.genesysgo.net))
  * SOLANAPAY - Solana Pay/GenesysGo endpoint ([solanapay.genesysgo.net](https://solanapay.genesysgo.net))
* devnet
  * SOLANA - Solana endpoint ([api.devnet.solana.com](https://api.devnet.solana.com))
* testnet
  * SOLANA - Solana endpoint ([api.testnet.solana.com](https://api.testnet.solana.com))


# API Reference

Dive into the specifics of each API endpoint by checking out our complete documentation.

## transaction.php

Verifying Solana transactions:

{% content-ref url="/pages/U6erLmL1XKF9VRLPfFoN" %}
[transaction.php](/reference/api-reference/transaction)
{% endcontent-ref %}

## token\_transaction.php

Verifying SPL token transactions:

{% content-ref url="/pages/NcZkn5zsY7OFUuutj7si" %}
[token\_transaction.php](/reference/api-reference/token-transaction)
{% endcontent-ref %}

## signature.php

Verifying signed messages:

{% content-ref url="/pages/eGLeuGoE4yZ21QHpqkWo" %}
[signature.php](/reference/api-reference/signature)
{% endcontent-ref %}

##


# transaction.php

Verifies a Solana transaction and the amount of Solana sent

## Verifies the details of a Solana transaction made through SOL Pay

<mark style="color:blue;">`GET`</mark> `https://solpay.solblaze.org/transaction.php`

The transaction endpoint takes in two parameters: `to` and `txid`. The `to` parameter is for the recipient address, and the `txid` is for the transaction signature (which can be obtained through one of the following transaction functions: [sendSolanaLamports](/reference/sdk-reference/send-solana-lamports), [sendSolana](/reference/sdk-reference/send-solana), [signTransaction](/reference/sdk-reference/sign-transaction)). The endpoint returns the sender address and the number of lamports sent.

#### Query Parameters

| Name                                   | Type   | Description                                |
| -------------------------------------- | ------ | ------------------------------------------ |
| to<mark style="color:red;">\*</mark>   | string | recipient address                          |
| txid<mark style="color:red;">\*</mark> | string | transaction signature                      |
| network                                | string | mainnet-beta (default), devnet, or testnet |

{% tabs %}
{% tab title="200: OK success - the transaction details are returned" %}

```javascript
{
    "status": "success",
    "transaction": {
        "lamports": 10000,
        "amount": 1.0e-5,
        "from": "SENDER_ADDRESS"
    }
}
```

{% endtab %}

{% tab title="200: OK error - could not find transaction " %}

```javascript
{
    "status": "error",
    "error": "There was no transaction with the specified txid made through SOL Pay."
}
```

{% endtab %}

{% tab title="200: OK error - missing parameters" %}

```javascript
{
    "status": "error",
    "error": "Missing parameters, endpoint requires the following fields: to, txid."
}
```

{% endtab %}

{% tab title="200: OK error - maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in maintenance mode, please try again in a few minutes."
}
```

{% endtab %}

{% tab title="200: OK error - extended maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in extended maintenance mode, please try again later."
}
```

{% endtab %}

{% tab title="200: OK error - unknown" %}

```javascript
{
    "status": "error",
    "error": "An unknown error occurred, please try again in a few minutes"
}
```

{% endtab %}
{% endtabs %}

### Example Request:

```
https://solpay.solblaze.org/transaction.php?to=RECIPIENT_ADDRESS&txid=TRANSACTION_SIGNATURE&network=mainnet-beta
```


# token\_transaction.php

Verifies an SPL token transaction and the amount of tokens sent

## Verifies the details of an SPL token transaction made through SOL Pay

<mark style="color:blue;">`GET`</mark> `https://solpay.solblaze.org/transaction.php`

The transaction endpoint takes in three parameters: `to`, `txid`, and `token`. The `to` parameter is for the recipient address, the `txid` is for the transaction signature (which can be obtained through one of the following transaction functions: [sendTokensDecimal](/reference/sdk-reference/send-tokens-decimal), [sendTokens](/reference/sdk-reference/send-tokens), [signTransaction](/reference/sdk-reference/sign-transaction)), and the `token` is for the token mint address. The endpoint returns the sender address and the number of tokens sent (in both decimal and integer form).

#### Query Parameters

| Name                                    | Type   | Description                                |
| --------------------------------------- | ------ | ------------------------------------------ |
| to<mark style="color:red;">\*</mark>    | string | recipient address                          |
| txid<mark style="color:red;">\*</mark>  | string | transaction signature                      |
| token<mark style="color:red;">\*</mark> | string | token address                              |
| network                                 | string | mainnet-beta (default), devnet, or testnet |

{% tabs %}
{% tab title="200: OK success - the transaction details are returned" %}

```javascript
{
    "status": "success",
    "transaction": {
        "amount": 10000,
        "amount_decimal": 1.0e-5,
        "decimals": 9,
        "from": "SENDER_ADDRESS"
    }
}
```

{% endtab %}

{% tab title="200: OK error - could not find transaction " %}

```javascript
{
    "status": "error",
    "error": "There was no transaction with the specified txid made through SOL Pay."
}
```

{% endtab %}

{% tab title="200: OK error - missing parameters" %}

```javascript
{
    "status": "error",
    "error": "Missing parameters, endpoint requires the following fields: to, txid, token."
}
```

{% endtab %}

{% tab title="200: OK error - maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in maintenance mode, please try again in a few minutes."
}
```

{% endtab %}

{% tab title="200: OK error - extended maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in extended maintenance mode, please try again later."
}
```

{% endtab %}

{% tab title="200: OK error - unknown" %}

```javascript
{
    "status": "error",
    "error": "An unknown error occurred, please try again in a few minutes"
}
```

{% endtab %}
{% endtabs %}

### Example Request:

```
https://solpay.solblaze.org/token_transaction.php?to=RECIPIENT_ADDRESS&txid=TRANSACTION_SIGNATURE&token=TOKEN_ADDRESS&network=mainnet-beta
```


# signature.php

Verifies a signed message made by the user's wallet

## Verifies a signed message

<mark style="color:blue;">`GET`</mark> `https://solpay.solblaze.org/signature.php`

The signature endpoint takes in three parameters: address, message, and signature. The address parameter is for the signing address, the message is for the text which was signed, and the signature is for the signed message (which can be obtained through [signMessage](/reference/sdk-reference/sign-message)). The endpoint returns whether the signature is valid.

#### Query Parameters

| Name                                        | Type   | Description     |
| ------------------------------------------- | ------ | --------------- |
| address<mark style="color:red;">\*</mark>   | string | signing address |
| message<mark style="color:red;">\*</mark>   | string | original text   |
| signature<mark style="color:red;">\*</mark> | string | signed text     |

{% tabs %}
{% tab title="200: OK success - the signature is valid" %}

```javascript
{
    "status": "success",
    "verified": true
}
```

{% endtab %}

{% tab title="200: OK success - the signature is invalid" %}

```javascript
{
    "status": "success",
    "verified": false
}
```

{% endtab %}

{% tab title="200: OK error - missing parameters" %}

```javascript
{
    "status": "error",
    "error": "Missing parameters, endpoint requires the following fields: address, message, signature."
}
```

{% endtab %}

{% tab title="200: OK error - maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in maintenance mode, please try again in a few minutes."
}
```

{% endtab %}

{% tab title="200: OK error - extended maintenance mode" %}

```javascript
{
    "status": "error",
    "error": "SOL Pay is in extended maintenance mode, please try again later."
}
```

{% endtab %}

{% tab title="200: OK error - unknown" %}

```javascript
{
    "status": "error",
    "error": "An unknown error occurred, please try again in a few minutes."
}
```

{% endtab %}
{% endtabs %}

### Example Request:

```
https://solpay.solblaze.org/signature.php?address=SIGNING_ADDRESS&message=MESSAGE&signature=SIGNATURE
```


