npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

decentralized-payments

v0.0.7

Published

A simplified client to integrate payment system for cosmos blockchains

Downloads

17

Readme

decentralized-payments

On frontend

install package using command

npm install decentralized-payments

Usage

To check currently supported chains

import {supportedChains} from "decentralized-payments"

console.log(supportedChains())

To make payment Client

import {getPaymentClient} from "decentralized-payments"

// to build a client from keplr signer (keplr has to be installed on frontend)
const client = await getPaymentClient("osmosis-1");

or

// to builder a client from mnemonic (DirectSecp256k1HdWallet)
const client = await getPaymentClient("osmosis-1", {
    useMnemonic: true,
    mnemonic: "mnemonic xyz"
  });
Note: It is advised to use the first version as it is more secure

Side effect on payment success

pass in a callback in case you want perform some effects if the the transaction is successful or you want to hit the payment verification endpoint on the server

const informServer = (chainID: string, txHash: string) => {
// hit server
// axios.post(paymentServerEndpoint);
}

const client = await getPaymentClient("osmosis-1", {

    useMnemonic: true,
    mnemonic: "mnemonic xyz",
    onTxSuccess: informServer

});

// or

const client2 = await getPaymentClient("osmosis-1", {
    onTxSuccess: informServer
});

To make payment

// These are minimal mandatory fields for a payment system to work
    const txHash = await client.makePayment({
      from: yourChainAddress,
      to: productOwnerChainAddress,
      amount: productCost,
      denom: chainDenom,
      memo: protocolParams,
    });

Memo to communication params between frontend and server

Memo: protocolParams

this is a very important field to communicate the buyer's details to the server so that server can process the business logic after confirming the payment

Example:

    // lets say the product is a video
    // the server needs the gmail address of the buyers to sent the video after confirming the payment

    interface Params {
        gmail: string
    }

    const params = {
        gmail: "[email protected]"
    }

    // pass it after converting it to a json string

    const memo = JSON.stringify(params);

    // so when processing the payment from on server, the server can parse the params

    const memo = tx.memo
    const params = JSON.parse(memo);

    const gmail = params.gmail

On server

To get validation Client

Example:


import {getValidationClient} from "decentralized-payments"

// existing chain configuration i.e node rest url
const client = getValidationClient(chainID);

// or

// for trust minimization, use your own or the familiar node endpoint

const client2 = getValidationClient(chainID, url);

define validation and businness logic callbacks

  1. isValid callback: to validate the the payment details of the transaction

Example:


// A simple implementation is check if the transaction amount >= the product amount and the transaction recipient == the seller's address
const isValid = (params) => {
  return (
    params.amount >= productCost &&
    params.recipient === sellerAddress
  );
};
  1. OnSuccess callback: this is where the core logic of the product transfer should be written. It will be triggered if the payment is success

Example

const onSuccess = (params) => {
  // write the business logic

  // update the db
  // transfer the product
  // etc..
};

Call the payment verification and processing method

Example:


 client.processTransaction(txHash, isValid, onSuccess);

If you have any query, dm me on my linkedin

https://www.linkedin.com/in/saitejae/