Quick Start

Get started with the SDK in under 5 minutes!

Import the SDK

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

Connect to the Solana Network

Connect to Default RPC Endpoint:

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

Connect to Custom RPC Endpoint:

(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"
})();

Connect Wallet

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

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.

Send Transaction

Send Solana Lamports

(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
})();

Send Solana

Important:

(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
})();

Verify Transaction

Important:

Verifies the details of a transaction made through SOL Pay

GET 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*

string

recipient address

txid*

string

transaction signature

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

Example Verification URL

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

Example

Frontend

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

Backend

// 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
}

Important:

Last updated