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.
You can install the package using yarn, npm or pnpm:
yarn add @blinkbitcoin/mavapay-client
npm install @blinkbitcoin/mavapay-client
pnpm add @blinkbitcoin/mavapay-client
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>",
})
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()
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()
NGNKOBO
: Nigerian Naira in KoboZARCENT
: South African Rand in Cents
type Network = "mainnet" | "signet" | "regtest"
type AuthConfig = {
apiKey: string
network: Network
}
To run and build the Mavapay Client locally, follow these steps:
- Install
nix
with flakes enabled - Install
direnv
and configure it for your shell
All commands must be executed within the nix
environment.
nix develop -c pnpm install
Build production (distribution) files in the dist/
folder:
nix develop -c pnpm build
Run tests using Jest:
nix develop -c pnpm test
To test this library locally in a different project, you can use npm link
or yarn link
.
Although the project uses
pnpm
internally, it can be consumed by other projects usingnpm
oryarn
.
In the root of the mavapay-client
project:
nix develop -c pnpm install
Build project (distribution) files in the dist/
folder:
nix develop -c pnpm build
Creates a global symbolic link to the library so it can be used locally in other projects during development.
npm link
# or
yarn link
In your test project folder:
npm link @blinkbitcoin/mavapay-client
# or
yarn link @blinkbitcoin/mavapay-client
Now you can import and use the library like this:
import { mavapayClient } from "@blinkbitcoin/mavapay-client"
Every time you change the library, run:
nix develop -c pnpm build
Your test project will automatically use the updated build.
In your test project:
npm unlink @blinkbitcoin/mavapay-client
# or
yarn unlink @blinkbitcoin/mavapay-client
In the library folder:
npm unlink
# or
yarn unlink
See npm link or yarn link for more.
This library was developed based on:
- Mavapay API Documentation – Official RESTful API reference for Mavapay (used to send Bitcoin to Nigeria and other countries).