npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

reflink-sdk

v0.1.8

Published

SDK for interacting with the Reflink Solana program via Anchor.

Downloads

16

Readme

Reflink SDK

A Solana-based affiliate and referral program SDK for managing merchant-affiliate relationships and processing referral payments in SOL and SPL tokens.

Overview

Reflink SDK provides a simple way to implement affiliate marketing programs on the Solana blockchain, allowing:

  • Merchants to register and set commission rates
  • Affiliates to register and earn commissions
  • Processing referral payments in both SOL and SPL tokens
  • Tracking all referral transactions on-chain

Features

  • ✅ Register as an affiliate
  • ✅ Register as a merchant with configurable commission rates
  • ✅ Process referral payments in SOL
  • ✅ Process referral payments in SPL tokens
  • ✅ Update merchant commission rates
  • ✅ Toggle merchant active status
  • ✅ Fetch affiliate and merchant data
  • ✅ Get referral history for merchants and affiliates

Installation

npm install reflink-sdk
# or
yarn add reflink-sdk

Getting Started

Initialization

import { Connection, Keypair } from "@solana/web3.js";
import { Wallet } from "@coral-xyz/anchor";
import ReflinkSDK from "reflink-sdk";

// Create a wallet from a keypair
const keypair = Keypair.generate(); // Or load from elsewhere
const wallet = new Wallet(keypair);

// Connect to Solana
const connection = new Connection("https://api.devnet.solana.com", "confirmed");

// Initialize the SDK
const reflinkSDK = new ReflinkSDK(connection, wallet);

Using with React and Wallet Adapter

import { useWallet } from "@solana/wallet-adapter-react";
import { Connection, PublicKey } from "@solana/web3.js";
import { Wallet } from "@coral-xyz/anchor";
import ReflinkSDK from "reflink-sdk";

function MyComponent() {
  const wallet = useWallet();
  const connection = new Connection("https://api.devnet.solana.com", "confirmed");
  
  const sdk = new ReflinkSDK(connection, wallet as unknown as Wallet);
  
  // Now you can use sdk methods...
}

Usage Examples

Register as an Affiliate

const registerAffiliate = async () => {
  try {
    const txSignature = await reflinkSDK.registerAffiliate();
    console.log("Successfully registered as affiliate:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to register as affiliate:", error);
    throw error;
  }
};

Register as a Merchant

const registerMerchant = async (commissionBps = 500) => { // 5% commission
  try {
    const txSignature = await reflinkSDK.registerMerchant(commissionBps);
    console.log("Successfully registered as merchant:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to register as merchant:", error);
    throw error;
  }
};

Process SOL Referral Payment

const processSolReferral = async (
  merchantPubkey,
  affiliatePubkey,
  merchantWallet,
  affiliateWallet,
  amountSol
) => {
  try {
    const amount = reflinkSDK.solToLamports(amountSol);
    
    const txSignature = await reflinkSDK.processReferralSol(
      new PublicKey(merchantPubkey),
      new PublicKey(affiliatePubkey),
      new PublicKey(merchantWallet),
      new PublicKey(affiliateWallet),
      amount
    );
    
    console.log("Successfully processed SOL referral:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to process SOL referral:", error);
    throw error;
  }
};

Process Token Referral Payment

const processTokenReferral = async (
  merchantPubkey,
  affiliatePubkey,
  merchantTokenAccount,
  affiliateTokenAccount,
  tokenMint,
  amount
) => {
  try {
    const txSignature = await reflinkSDK.processReferralToken(
      new PublicKey(merchantPubkey),
      new PublicKey(affiliatePubkey),
      new PublicKey(merchantTokenAccount),
      new PublicKey(affiliateTokenAccount),
      new PublicKey(tokenMint),
      amount
    );
    
    console.log("Successfully processed token referral:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to process token referral:", error);
    throw error;
  }
};

Update Merchant Commission

const updateCommission = async (merchantPubkey, newCommissionBps) => {
  try {
    const txSignature = await reflinkSDK.updateMerchantCommission(
      new PublicKey(merchantPubkey),
      newCommissionBps
    );
    
    console.log("Successfully updated commission:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to update commission:", error);
    throw error;
  }
};

Toggle Merchant Status

const toggleMerchantStatus = async (merchantPubkey) => {
  try {
    const txSignature = await reflinkSDK.toggleMerchantStatus(
      new PublicKey(merchantPubkey)
    );
    
    console.log("Successfully toggled merchant status:", txSignature);
    return txSignature;
  } catch (error) {
    console.error("Failed to toggle merchant status:", error);
    throw error;
  }
};

Get Affiliate Data

const getAffiliateData = async (affiliatePubkey) => {
  try {
    const data = await reflinkSDK.getAffiliateData(
      new PublicKey(affiliatePubkey)
    );
    console.log("Affiliate data:", data);
    return data;
  } catch (error) {
    console.error("Failed to fetch affiliate data:", error);
    throw error;
  }
};

Get Referrals for an Affiliate

const getAffiliateReferrals = async (affiliatePubkey) => {
  try {
    const referrals = await reflinkSDK.getAffiliateReferrals(
      new PublicKey(affiliatePubkey)
    );
    console.log("Affiliate referrals:", referrals);
    return referrals;
  } catch (error) {
    console.error("Failed to fetch affiliate referrals:", error);
    throw error;
  }
};

React Integration

The SDK can be easily integrated with React applications using hooks:

import { useReflinkSDK } from './useReflinkSDK';

function MyComponent() {
  const {
    registerAsAffiliate,
    registerAsMerchant,
    processSolReferral,
    processTokenReferral,
    updateCommission,
    toggleMerchantStatus,
    getAffiliateData,
    getAffiliateReferrals,
  } = useReflinkSDK();
  
  const handleRegisterAffiliate = async () => {
    try {
      const tx = await registerAsAffiliate();
      // Handle success
    } catch (error) {
      // Handle error
    }
  };
  
  // Rest of your component...
}

Program Structure

The SDK interfaces with a Solana program that includes the following account types:

  • Affiliate: Represents an affiliate account on-chain
  • Merchant: Represents a merchant with commission settings
  • Referral: Records a referral transaction between merchant and affiliate

Development

Prerequisites

  • Node.js 14+
  • Yarn or npm
  • Solana CLI tools (for local development/testing)

Local Setup

# Clone the repository
git clone https://github.com/reflink-labs/reflink-sdk.git
cd reflink-sdk

# Install dependencies
yarn install

# Build the SDK
yarn build

License

MIT