@blinkbitcoin/mavapay-client
v0.0.3
Published
TypeScript client library for **Mavapay Money API**. This library can be used in front-end applications such as web and mobile wallets to transfer Bitcoin to Nigeria.
Readme
Mavapay-client
TypeScript client library for Mavapay Money API. This library can be used in front-end applications such as web and mobile wallets to transfer Bitcoin to Nigeria.
Installation
You can install the package using yarn, npm or pnpm:
using yarn:
yarn add @blinkbitcoin/mavapay-clientusing npm:
npm install @blinkbitcoin/mavapay-clientusing pnpm:
pnpm add @blinkbitcoin/mavapay-clientUsage
Authentication
Before calling any API, you need to configure authentication:
import { mavapayClient } from "@blinkbitcoin/mavapay-client"
mavapayClient.configureAuth({
network: "signet", // Can be "mainnet" | "signet" | "regtest"
apiKey: "<YOUR_MAVAPAY_API_KEY>",
})getBanksByCountry
Retrieve a list of banks available for a given country:
import { mavapayClient } from "@blinkbitcoin/mavapay-client"
mavapayClient.configureAuth({
network: "signet",
apiKey: "<YOUR_MAVAPAY_API_KEY>",
})
async function fetchBanks() {
try {
const banks = await mavapayClient.getBanksByCountry("NG") // "NG" = Nigeria
if ("type" in banks) {
console.error("Error retrieving banks:", banks.message)
return
}
console.log("Banks retrieved:", banks) // Returns an array of bank objects
} catch (error) {
console.error("Unexpected error:", error)
}
}
fetchBanks()getQuote
Retrieve a quote to send Bitcoin to a bank account:
import { mavapayClient } from "@blinkbitcoin/mavapay-client"
mavapayClient.configureAuth({
network: "signet",
apiKey: "<YOUR_MAVAPAY_API_KEY>",
})
async function fetchQuote() {
try {
const quote = await mavapayClient.getQuote({
amount: 300000,
sourceCurrency: "BTCSAT",
targetCurrency: "NGNKOBO",
paymentMethod: "LIGHTNING",
paymentCurrency: "NGNKOBO",
autopayout: true,
beneficiary: {
bankAccountNumber: "0123456789",
bankAccountName: "olaolu olajide",
bankCode: "090267",
bankName: "GTBANK PLC",
},
})
if ("type" in quote) {
console.error("Error retrieving quote:", quote.message)
return
}
console.log("Quote:", quote) // Return the Lightning payment details
} catch (error) {
console.error("Unexpected error:", error)
}
}
fetchQuote()Currency Types
NGNKOBO: Nigerian Naira in KoboZARCENT: South African Rand in Cents
Type Definitions
type Network = "mainnet" | "signet" | "regtest"
type AuthConfig = {
apiKey: string
network: Network
}Local Development
1. Run the Mavapay Client Locally
To run and build the Mavapay Client locally, follow these steps:
Prerequisites
- Install
nixwith flakes enabled - Install
direnvand configure it for your shell
All commands must be executed within the nix environment.
Install Dependencies
nix develop -c pnpm installBuild
Build production (distribution) files in the dist/ folder:
nix develop -c pnpm buildTest
Run tests using Jest:
nix develop -c pnpm test2. Link the Library into Another Project
To test this library locally in a different project, you can use npm link or yarn link.
Although the project uses
pnpminternally, it can be consumed by other projects usingnpmoryarn.
Step 1: Build and Link the Library
In the root of the mavapay-client project:
Install Dependencies
nix develop -c pnpm installBuild
Build project (distribution) files in the dist/ folder:
nix develop -c pnpm buildCreates a global symbolic link to the library so it can be used locally in other projects during development.
npm link
# or
yarn linkStep 2: Link it in your test project
In your test project folder:
npm link @blinkbitcoin/mavapay-client
# or
yarn link @blinkbitcoin/mavapay-clientNow you can import and use the library like this:
import { mavapayClient } from "@blinkbitcoin/mavapay-client"Step 3: Rebuild on Changes
Every time you change the library, run:
nix develop -c pnpm buildYour test project will automatically use the updated build.
Step 4: Unlink (when done)
In your test project:
npm unlink @blinkbitcoin/mavapay-client
# or
yarn unlink @blinkbitcoin/mavapay-clientIn the library folder:
npm unlink
# or
yarn unlinkSee npm link or yarn link for more.
References
This library was developed based on:
- Mavapay API Documentation – Official RESTful API reference for Mavapay (used to send Bitcoin to Nigeria and other countries).
