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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@macalinao/zod-solana

v0.3.0

Published

Zod schemas for Solana types with @solana/kit integration

Downloads

944

Readme

@macalinao/zod-solana

npm version

Zod schemas for Solana types with @solana/kit integration. Provides type-safe validation and transformation for Solana addresses.

Installation

npm install @macalinao/zod-solana
# or
yarn add @macalinao/zod-solana
# or
bun add @macalinao/zod-solana

Peer Dependencies

This package requires the following peer dependencies:

  • @solana/kit (>=1.0.0)
  • zod (>=3.0.0 or >=4.0.0)

Usage

Basic Address Validation

import { addressSchema } from "@macalinao/zod-solana";

// Parse and validate a Solana address
const address = addressSchema.parse("11111111111111111111111111111111");
// Returns: Address type from @solana/kit

// Safe parsing with error handling
const result = addressSchema.safeParse("invalid-address");
if (result.success) {
  console.log("Valid address:", result.data);
} else {
  console.log("Invalid address:", result.error.issues[0].message);
  // Output: "Invalid Solana address"
}

With React Hook Form

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { addressSchema } from "@macalinao/zod-solana";

const formSchema = z.object({
  recipient: addressSchema,
  amount: z.number().positive(),
});

type FormData = z.infer<typeof formSchema>;

function SendTokenForm() {
  const { register, handleSubmit, formState: { errors } } = useForm<FormData>({
    resolver: zodResolver(formSchema),
  });

  const onSubmit = (data: FormData) => {
    // data.recipient is typed as Address
    console.log("Sending to:", data.recipient);
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("recipient")} placeholder="Recipient address" />
      {errors.recipient && <span>{errors.recipient.message}</span>}

      <input {...register("amount", { valueAsNumber: true })} placeholder="Amount" />
      {errors.amount && <span>{errors.amount.message}</span>}

      <button type="submit">Send</button>
    </form>
  );
}

Type Inference

import * as z from "zod";
import { addressSchema } from "@macalinao/zod-solana";

// Infer the Address type
type SolanaAddress = z.infer<typeof addressSchema>;
// Type: Address from @solana/kit

// Use in your schemas
const walletSchema = z.object({
  owner: addressSchema,
  tokenAccounts: z.array(addressSchema),
  lamports: z.number(),
});

type Wallet = z.infer<typeof walletSchema>;

Features

  • Type-safe: Validates and transforms strings to Solana Address type
  • Zod v3 & v4 compatible: Works with both major versions of Zod
  • Comprehensive validation: Checks for valid base58 encoding and address format
  • TypeScript support: Full type inference and autocompletion
  • Framework agnostic: Use with any JavaScript/TypeScript framework
  • Well tested: Comprehensive test suite with edge cases

API

addressSchema

A Zod schema that validates Solana addresses.

  • Input: string - A potential Solana address
  • Output: Address - A validated Address type from @solana/kit
  • Errors: Throws/returns error with message "Invalid Solana address" for invalid inputs

Examples

Validating Multiple Addresses

import * as z from "zod";
import { addressSchema } from "@macalinao/zod-solana";

const multiSigSchema = z.object({
  signers: z.array(addressSchema).min(2),
  threshold: z.number().min(1),
});

const multisig = multiSigSchema.parse({
  signers: [
    "11111111111111111111111111111111",
    "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  ],
  threshold: 2,
});

Custom Error Messages

const customAddressSchema = addressSchema.describe("Wallet address");

// Or with Zod's built-in error customization
const recipientSchema = z
  .string()
  .pipe(addressSchema)
  .describe("Recipient wallet address");

Development

# Install dependencies
bun install

# Run tests
bun test

# Build the package
bun run build

# Run linting
bun run lint

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Related

  • @macalinao/grill - Modern Solana development kit for React applications
  • @solana/kit - Solana development toolkit
  • zod - TypeScript-first schema validation

License

Copyright (c) 2025 Ian Macalinao. Licensed under the Apache-2.0 License.