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

thirdweb-payment

v0.0.281

Published

![example](https://github.com/BankkRoll/thirdweb-payment/assets/106103625/532d6f80-4b49-47bf-aa1e-58b27634ce5c)

Downloads

7

Readme

thirdweb-payment Button Component

example

Overview

The Payment Button component is a reusable React component for handling Ethereum payments. It allows users to initiate a payment by specifying the recipient's Ethereum address and the amount to send.

Installation & Usage

Step 1: Configuration

In your app, configure the @thirdweb-dev/react package as follows:

  1. Install the required packages:

    npm i @thirdweb-dev/react @thirdweb-dev/sdk ethers@^5
  2. Initialize the ThirdwebProvider component with the desired chain and client ID:

     // More info here: https://portal.thirdweb.com/react/react.thirdwebprovider
     import { ThirdwebProvider } from "@thirdweb-dev/react";
    
     function MyApp() {
     return (
         <ThirdwebProvider
         activeChain="ethereum"
         clientId="your-client-id"
         >
         <YourApp />
         </ThirdwebProvider>
       );
     }

Step 2: Button Component

To use the Payment Button component in your project, follow these steps:

  1. Install the package via npm:

    npm install thirdweb-payment
  • To ensure the component is styled correctly, import the CSS file from the dist folder of the thirdweb-payment package:

    import 'thirdweb-payment/dist/PaymentButton.css';
  1. Now, you can use the PaymentButton component in your React application as shown below:
import React from 'react';
import { PaymentButton } from 'thirdweb-payment';
import 'thirdweb-payment/dist/PaymentButton.css';

function Home() {

  return (
    <div>
        <PaymentButton
          // Required props
          recipient="0x1234567890abcdef"         // Ethereum address of the recipient
          amount="0.001"                         // Amount in Ether to send

          // Optional props
          className="custom-payment-button"      // Custom className for the button
          termsText="Custom terms text"          // Custom terms text
          buttonText="Pay with Ether"            // Custom text for the button
          icon="💰"                              // Custom icon for the button
          onPaymentSuccess={() => console.log('Payment Successful')}   // Custom success action
          onPaymentError={(error) => console.error('Payment Error:', error)} // Custom error action
          onTransactionLog={(log) => console.log('Transaction Log:', log)}  // Custom Transaction Logging
          
          // Custom classes (*YOU MAY NEED TO USE THE "!important" FLAG IN YOUR CSS TO OVERRIDE DEFAULT STYLES*)
          customClasses={{
            contentContainer: "custom-content-container",          // Custom className for the container
            button: "custom-button-style",                         // Custom className for the connect/buy button

            modalOverlay: "custom-modal-overlay",                  // Custom className for the modal overlay
            modalContent: "custom-modal-content",                  // Custom className for the modal content 
            modalButton: "custom-modal-button",                    // Custom className for the base modal buttons
            modalButtonSuccess: "custom-modal-button-success",     // Custom className for the modal button success 
            modalButtonCancel: "custom-modal-button-cancel",       // Custom className for the modal button cancel
            modalActions: "custom-modal-actions",                  // Custom className for the modal actions container
            modalHeader: "custom-modal-header",                    // Custom className for the modal
            modalParagraph: "custom-modal-paragraph",              // Custom className for the modal

            loadingSpinnerContainer: "custom-loading-spinner-container",  // Custom className for the loading spinner container
            loadingSpinner: "custom-loading-spinner",              // Custom className for the loading spinner

            transactionDetailsContainer: "custom-transaction-details-container", // Custom className for the transaction details container 
            transactionDetailRow: "custom-transaction-detail-row",              // Custom className for the transaction details row  
            transactionDetailLabel: "custom-transaction-detail-label",          // Custom className for the transaction details label
            transactionDetailValue: "custom-transaction-detail-value",          // Custom className for the transaction details value
            transactionDetailSymbol: "custom-transaction-detail-symbol",        // Custom className for the transaction details symbol
            transactionAddDetailAmount: "custom-transaction-add-detail-amount", // Custom className for the transaction details add amount
            transactionSubtractDetailAmount: "custom-transaction-subtract-detail-amount",    // Custom className for the transaction details subtract amount

            termsContainer: "custom-terms-container",                      // Custom className for the terms container
            termsCheckBox: "custom-terms-check-box",                       // Custom className for the terms checkbox
            termsCheckBoxLabel: "custom-terms-check-box-label",            // Custom className for the terms checkbox label

            additionalPaymentButton: "custom-additional-payment-button",   // Custom className additional payment button
            errorBlock: "custom-error-block",                              // Custom className error block warning container
          }}
        />
    </div>
  );
}

export default Home;

Props

The PaymentButton component accepts the following props:

  • recipient (string): Ethereum address of the recipient of payments.
  • amount (string): Amount in Ether to send.
  • className (string, optional): Custom className for the button.
  • buttonText (string, optional): Custom text for the button.
  • termsText (string, optional): Custom text for the terms label.
  • icon (React.ReactNode, optional): Custom icon element to display next to the button text.
  • customClasses (object, optional): Custom CSS styles for different parts of the component, including button, modal overlay, modal content, modal buttons, and loader.
  • onPaymentSuccess (function, optional): Callback function for successful payment.
  • onPaymentError (function, optional): Callback function for payment error.
  • onTransactionLog (function, optional): Callback function for transaction logging.

Logging

The onTransactionLog event logging can be used to obtain transaction details following the structure below:

  1. Successful Payment

    {
      "type": "success",
      "userAddress": "0xUserAddress...",
      "transactionHash": "0xabc123...",
      "from": "0xSenderAddress...",
      "to": "0xRecipientAddress...",
      "amount": "1000000000000000000", // 1 ETH in wei
      "nonce": 0,
      "gasLimit": "21000",
      "gasPrice": "50000000000", // 50 Gwei in wei
      "maxFeePerGas": null,
      "maxPriorityFeePerGas": null,
      "chainId": 1,
      "initialAmount": "1", // ETH
      "remainingAmount": "0.0",
      "blockNumber": 123456,
      "timeStamp": "2023-01-01T00:00:00.000Z"
    }
  2. Payment Error

    {
      "type": "error",
      "errorMessage": "Insufficient funds",
      "errorDetails": "Error stack or details here",
      "userAddress": "0xUserAddress...",
      "transactionData": {
        "to": "0xRecipientAddress...",
        "value": "1000000000000000000",
        "initialAmount": "1"
      },
      "transactionResponseHash": "0xabc123...",
      "errorTime": "2023-01-01T00:00:00.000Z"
    }
  3. Successful Additional Payment

    {
      "type": "additionalPaymentSuccess",
      "originalTransactionHash": "0xabc123...",
      "userAddress": "0xUserAddress...",
      "transactionHash": "0xdef456...",
      "from": "0xSenderAddress...",
      "to": "0xRecipientAddress...",
      "amount": "500000000000000000", // 0.5 ETH in wei
      "nonce": 1,
      "gasLimit": "21000",
      "gasPrice": "55000000000", // 55 Gwei in wei
      "maxFeePerGas": null,
      "maxPriorityFeePerGas": null,
      "chainId": 1,
      "initialAmount": "1",
      "remainingAmount": "0.0",
      "blockNumber": 123457,
      "timeStamp": "2023-01-01T01:00:00.000Z"
    }
  4. Additional Payment Error

    {
      "type": "additionalPaymentError",
      "originalTransactionHash": "0xabc123...",
      "errorMessage": "Network error",
      "errorDetails": "Error stack or details here",
      "userAddress": "0xUserAddress...",
      "transactionData": {
        "to": "0xRecipientAddress...",
        "value": "500000000000000000", // 0.5 ETH in wei
        "initialAmount": "1",
        "remainingAmount": "0.5"
      },
      "transactionResponseHash": "0xdef456...",
      "errorTime": "2023-01-01T01:00:00.000Z"
    }

License

This component is released under the MIT License.