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

solana-program

v0.3.6

Published

Higher-level client interface for interacting with on-chain Solana programs

Readme

Solana Program

solana-program builds upon @solana/web3.js with the intent of reducing the amount of boilerplate code and lower-level data wrangling necessary when developing client-side Solana apps. Our goal is to provide a more intuitive, object-oriented API.

Installing

yarn add solana-program or npm install solana-program.

Building & Executing Instructions

Custom instructions can be built using the InstructionBuilder API. For example:

const instr = program
  .instruction()
  .account(user.publicKey, { isSigner: true, isWritable: true })
  .account(dataAccountPublicKey, { isWritable: true })
  .data(data);

You can add one or more InstructionBuilder objects to a transaction, using TransactionBuilder, like so:

const tx = Solana.begin().add(instr).sign(user);
const signature = await tx.execute();

Querying Program Accounts

Querying in @solana/web3.js

In order to retrieve a program's accounts using @solana/web3.js, you normally have to use some form of the getProgramAccounts function. Queries can be filtered according to two main criteria:

  1. The size (in bytes) of the target account's data.
  2. Contents of specific slices of base58-encoded data.

Example:

Suppose we have an account that stores an initial "tag" byte, which indicates what "type" of account something is, as well as a "username" string and an "age" int. Using only web3.js to select accounts that match this pattern looks somehing like this:

const results = await getParsedProgramAccounts(programId, {
  encoding: 'jsonParsed',
  filters: [
    {
      memcmp: {
        offset: 0,
        bytes: b58.encode([1]),
      },
    },
    {
      memcmp: {
        offset: 2,
        bytes: b58.encode(Buffer.from('coolperson123')),
      },
    },
    {
      dataSize: 1 + 1 + 256,
    },
  ],
});

Querying in solana-program

In contrast, solana-program provides a more intuitive interface. The same query would be written like this:

// example data structure we're storing in account
class Comment extends ProgramObject {
  @field('u8')
  tag: number = 1;

  @field('u8')
  age?: number;

  @field('String', { space: 256 })
  username?: string;
}

// select all accounts with username glorp. note that the dataSize filter is
// automatically added; however, it can be set explicitly, via
// program.select(Comment).size(...)...
const accounts = await program
  .select(Comment)
  .match({ tag: 1, username: 'coolperson123' })
  .execute();

Basic Example

This is a complete example of building a client for a Solana program that simply initializes and sets a "lucky number" in an account.

class LuckyNumber extends ProgramObject {
  @field('u8')
  value?: number;
}

class LuckyNumberProgram extends Program {
  public async main(user: Keypair) {
    await Solana.initialize();

    const seed = 'lucky-number'
    const key = await this.deriveAddress(user.publicKey, seed);
    const account = await this.getAccount(LuckyNumber, luckNumberKey);
    const luckyNumber = Math.round(100 * Math.random());
    const tx = Solana.begin();

    if (account === null) {
      const space = 1;
      const instr = this.createAccountWithSeed(user, seed, key, space)
      console.log('creating "lucky number" account');
      tx.add(instr);
    }
    console.log('setting new "lucky number"');
    tx.add(this.setLuckyNumber(user, key, luckyNumber));

    const signature = await tx.sign(user).execute();
    console.log('transaction signature:', signature);
  }

  public setLuckyNumber(
    user: Address, key: Address, value: number,
  ): CustomInstructionBuilder {
    return this.instruction(0)  // 0 is the OP code of the instruction
      .account(user, { isWritable: true, isSigner: true });
      .account(key, { isWritable: true, });
      .data(new LuckyNumber({ value }))
  }
}