Web3 API (Solana)
Full decentralized integration using @solana/web3.js for Solana programs.
Overview
The Web3 API approach provides direct integration with Merso Solana programs using @solana/web3.js and Anchor. This is ideal for games that already have Solana infrastructure and want full control over transaction signing.
Requirements
-
✓
Solana Libraries@solana/web3.js v1.8+ and @coral-xyz/anchor
-
✓
Wallet ProviderPhantom, Solflare, or Backpack
-
✓
RPC EndpointAccess to Solana RPC (Helius, QuickNode, etc.)
Integration Steps
1. Install Dependencies
npm
npm install @solana/web3.js @coral-xyz/anchor @merso/solana-sdk
2. Initialize Merso Client
JavaScript
import { Connection, PublicKey } from '@solana/web3.js';
import { AnchorProvider } from '@coral-xyz/anchor';
import { MersoClient } from '@merso/solana-sdk';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = window.solana; // Phantom
const provider = new AnchorProvider(connection, wallet, {});
const merso = new MersoClient(provider);
3. Execute PNPL Purchase
JavaScript
// Build PNPL transaction
const { transaction, signers } = await merso.buildPNPLTransaction({
collection: new PublicKey(nftCollectionMint),
nftMint: new PublicKey(nftMintAddress),
price: 100_000_000, // 100 tokens (with decimals)
paymentMint: new PublicKey(tokenMintAddress)
});
// Sign and send
const signature = await wallet.signAndSendTransaction(transaction);
await connection.confirmTransaction(signature);