1.1.0 • Published 4 months ago

maswallet-nodejs v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

MasWallet Node.js SDK

A Node.js SDK for interacting with the MasWallet API. This SDK provides an easy-to-use wrapper for developers to integrate MasWallet's blockchain services into their applications.


Features

  • Simplified access to MasWallet API endpoints.
  • Supports both TypeScript and JavaScript.
  • Fully typed for a better developer experience.
  • Built-in error handling.
  • Supports customizable configurations.

Installation

npm install maswallet-nodejs

or

yarn add maswallet-nodejs

Quick Start

Import the SDK

// Using TypeScript or ES Module
import { ApiClient } from 'maswallet-nodejs';

// Using CommonJS
const { ApiClient } = require('maswallet-nodejs');

Initialize the Client

const client = new ApiClient({
  apiClientId: '<YOUR_API_KEY>',
  apiClientSecret: '<YOUR_API_SECRET>',
  baseUrl: 'https://wallet-api.maschain.com', // Optional: defaults to MasWallet's official base URL
});

Example Usage

Create a Transaction

const transaction = await client.createTransaction({
  walletAddress: '<WALLET_ADDRESS>',
  contractAddress: '<CONTRACT_ADDRESS>',
  abiFunction: '<ABI_FUNCTION>',
  functionArgs: ['<FUNCTION_ARG_1>', '<FUNCTION_ARG_2>'],
  redirectUrl: '<REDIRECT_URL>', // Optional: defaults to the current URL
});
console.log(transaction);

Documentation

Methods

createTransaction(params: TransactionParams): Promise<TransactionResponse>

Creates a new transaction on the MasWallet blockchain.

getTransaction(transactionId: string): Promise<TransactionDetails>

Retrieves details of a specific transaction.

For full method documentation, refer to the API Documentation.


Configuration

The ApiClient supports the following configuration options:

OptionTypeDefaultDescription
apiClientIdstringundefinedYour MasWallet API client ID.
apiClientSecretstringundefinedYour MasWallet API client secret.
baseUrlstringhttps://api.maschain.com/apiBase URL for the MasWallet API.
timeoutnumber5000Request timeout in milliseconds.

Error Handling

Errors thrown by the SDK are instances of MasWalletError, which provides the following properties:

  • code: Error code returned by the API.
  • message: A descriptive error message.
  • details: Additional error information (if any).

Example

try {
  const transaction = await client.createTransaction({ ... });
} catch (error) {
  if (error instanceof MasWalletError) {
    console.error('Error Code:', error.code);
    console.error('Error Message:', error.message);
  } else {
    console.error('An unexpected error occurred:', error);
  }
}
1.1.0

4 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago