Skip to main content

Prerequisites

Before installing the SDK, ensure you have:

Node.js or Runtime

  • Node.js 16+ (for Node.js environments)
  • Bun, Deno, or any modern JavaScript runtime

TypeScript (Optional)

  • TypeScript 5.0+ recommended for the best experience
  • Works with JavaScript projects too
You’ll need a Paystack account and API keys. Get yours at paystack.com

Package Installation

Install the SDK using your preferred package manager:

Install Peer Dependencies

The SDK requires Zod for runtime validation. Install it if you haven’t already:
The SDK requires Zod ^4.0.0. If you’re using an older version, you may need to upgrade.

Environment Setup

Get Your API Keys

Paystack provides two types of secret keys:
  • Test keys (sk_test_...) - For development and testing
  • Live keys (sk_live_...) - For production use
Never commit your secret keys to version control. Always use environment variables.

Configure Environment Variables

Create a .env file in your project root:
.env
Add .env to your .gitignore file to prevent accidentally committing secrets.

Environment-Specific Configuration

For different environments, use separate environment variables:
.env.example

TypeScript Configuration

For optimal TypeScript support, configure your tsconfig.json:
tsconfig.json
The SDK uses ES modules. Ensure your project is configured to support them.

Type Definitions

The SDK includes full TypeScript definitions. Import types as needed:
types.ts

Framework-Specific Setup

Node.js with Express

index.ts

Next.js (App Router)

No additional configuration needed. Use environment variables in .env.local:
.env.local
app/api/payment/route.ts

Bun

Bun has built-in environment variable support:
index.ts

Cloudflare Workers

Use Wrangler secrets for environment variables:
worker.ts

Deno

mod.ts

Verify Installation

Create a simple test file to verify your setup:
test.ts
Run the test:
If you see “Invalid secret key” error, check that your key starts with sk_test_ or sk_live_.

Common Issues

Ensure you’ve installed both @efobi/paystack and zod:
The SDK validates that your key starts with sk_test_ or sk_live_. Check your environment variables:
Ensure you’re using TypeScript 5.0 or higher:
If you’re using CommonJS, ensure your package.json has:
Or use .mjs file extensions.

Next Steps

Now that you have the SDK installed, you’re ready to build your first integration:

Quick Start Guide

Learn how to initialize transactions and verify payments