1.3.8 • Published 6 months ago

scribepay-sdk v1.3.8

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

scribepay-sdk

ScribePay SDK to interact with contracts for payments

ScribePay SDK

The ScribePay SDK is a library designed to streamline payment integration in projects or business. It provides on click solution for user to pay businesses in crypto.

Features

  • Native Payments: Easily send native cryptocurrency payments to a specified business address
  • ERC-20 Payments: Transfer ERC-20 tokens seamlessly
  • Dynamic Provider Support: Supports browser providers like MetaMask and custom provider URLs
  • Business Validation: Validates the business using an API key before enabling transactions

Installation

Install the SDK using npm:

npm install scribepay-sdk

Usage

Import the SDK

import {
  Payment,
  usePay,
  usePayErc20,
  ProviderConfig,
  useInitializeSDK,
} from "scribepay-sdk";

Initialization

You must initialize the SDK with your provider configuration before making any calls:

import { useInitializeSDK } from "scribepay-sdk";
 const providerConfig: ProviderConfig = {
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxx",
    provider: provider, // Change 'ethereum' to the actual provider if necessary
  };
  const { businessData } = useInitializeSDK(providerConfig);
  console.log(businessData, 'get business details')

Making Payments

Native Cryptocurrency Payment

import { usePay } from 'scribepay-sdk';

   const { payNativeToken, currencyResData } =    usePay({
     amount: "amount to Pay",
     expectedDelivery: 'uniax timestamp,
     fromCurrency: "currency to pay",
     token: { value: 'native token address',   label: "native token address" },
   });
 // currencyResData use to get the exchange of currency details

ERC-20 Token Payment

import { usePayErc20 } from 'scribepay-sdk';

    const {  payERC20Token ,currencyResData} = usePayErc20({
     amount: "amount to Pay",
     expectedDelivery: 'uniax timestamp,
     fromCurrency: "currency to pay",
     token: { value: 'erc20 token address',   label: "erc20 token address" },
   });
   // currencyResData use to get the exchange of currency details

Example Frontend Integration

import { ethers } from "ethers";
import {
  Payment,
  usePay,
  usePayErc20,
  ProviderConfig,
  useInitializeSDK,
} from "scribepay-sdk/src";
import { useEffect, useState } from "react";

const Transactions = () => {
  const [provider, setProvider] = useState<ethers.BrowserProvider | undefined>(
    undefined
  );
  const currentTime = Math.floor(Date.now() / 1000);
  const timePlus3Minutes = currentTime + 3 * 60;
  useEffect(() => {
    const { ethereum } = window;
    if (ethereum) {
      const newProvider = new ethers.BrowserProvider(ethereum);
      setProvider(newProvider);
    }
  }, []);
  const providerConfig: ProviderConfig = {
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxx",
    provider: provider, // Change 'ethereum' to the actual provider if necessary
  };
  const { businessData: bss } = useInitializeSDK(providerConfig);
  
  const handlePaymentSuccess = () => {
    console.log("Payment was successful!");
    // Perform any additional actions, such as navigation or showing a success message
  };

  const { payNativeToken, currencyResData } = usePay({
    amount: "amount to pay",
    expectedDelivery: "uniax timestamp",
    fromCurrency: "currency to pay",
    token: { value: "native token address", label: "native token label" },
  });

  const { payERC20Token } = usePayErc20({
    amount: "amount to pay",
    expectedDelivery: "uniax timestamp",
    fromCurrency: "currency to pay",
    token: { value: "erc20 token address", label: "erc20 token label" },
  });
  return (
    <div>
      <Payment
        amount="0.01"
        expectedDelivery={timePlus3Minutes}
        theme="dark"
        fromCurrency="PKR",
        onSuccess={handlePaymentSuccess}
      />
      <button onClick={payERC20Token} className="text-white">
        Pay ERC20
      </button>
      <button onClick={payNativeToken} className="text-white">
        Pay Native
      </button>
    </div>
  );
};

export default Transactions;

API Documentation

initialize(providerConfig)

Initializes the SDK with the given provider configuration.

Parameters:

  • providerConfig (object): Contains apiKey, providerUrlConfig, and/or provider

usePay

Makes a native cryptocurrency payment.

Parameters:

  • amount (string): The amount to be sent in ETH
  • expectedDelivery (number): The expectedDelivery tiem in uniax timestamp
  • fromCurrency (string): The currency being used for the payment.
  • token (object:{value:string, label: string}): The native token address and label fro payement

usePayErc20

Transfers ERC-20 tokens.

Parameters:

  • amount (string): The amount to be sent in ETH
  • expectedDelivery (number): The expectedDelivery tiem in uniax timestamp
  • fromCurrency (string): The currency being used for the payment.
  • token (object:{value:string, label: string}): The erc20 token address and label fro payement

Requirements

  • Node.js 19 or higher
  • ethers.js library
  • MetaMask or similar Ethereum wallet for browser integration

Contributing

Feel free to contribute by submitting issues or pull requests. Ensure you follow the project's coding guidelines and standards.

License

This SDK is licensed under the MIT License. See the LICENSE file for details.

Visit Us

For more information, visit our website: ScribePay

Support

For any issues or inquiries, please contact support@scribepay.org.

This project was made with love by the ScribePay team. ❤️

1.3.8

6 months ago

1.3.7

6 months ago

1.3.6

6 months ago

1.3.4

6 months ago

1.3.3

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.2.9

6 months ago

1.2.8

6 months ago

1.2.7

6 months ago

1.2.6

6 months ago

1.2.4

6 months ago

1.2.3

6 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

7 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

8 months ago

1.0.0

8 months ago

1.0.19

8 months ago