Skip to content

Getting Started

Prerequisites

  • .NET 8.0 or later
  • Safaricom Daraja API credentials (register here)

Installation

dotnet add package MpesaDarajaSDK

Initialize the Gateway

using Mpesa.Daraja;
using Mpesa.Daraja.Auth;

using var gateway = new DarajaGateway(consumerKey, consumerSecret, isLive: false);
await gateway.InitializeDarajaAsync();

Set isLive: true for production. This switches the base URL from sandbox (sandbox.safaricom.co.ke) to live (api.safaricom.co.ke).

The SDK refreshes tokens automatically — when you call any API method, it checks token validity and re-authenticates if needed.

Next Steps