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

blockloyal-library

v1.9.0

Published

- [Installing](#installing) - [Package manager](#package-manager) - [CDN](#cdn) - [Example](#example) - [License](#license)

Downloads

28

Readme

Table of Contents

Installing

Package manager

Using npm:

$ npm i blockloyal-library

Using yarn:

$ yarn add blockloyal-library

Once the package is installed, you can import the library using import or require approach:

import { getNftsForAddress } from 'blockloyal-library';

CDN

Using jsDelivr CDN (ES5 UMD browser module):

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/blockloyal-library.cjs.production.min.js"></script>

Examples

NPM implementation

Get NFTs for address

The getNftsForAddress function allows you to get an array of non-fungible tokens (NFTs) minted by BlockLoyal that are owned by a given Ethereum address.

Example:

import { getNftsForAddress } from 'blockloyal-library';

// Get blockloyal's nfts associated with a wallet
getNftsForAddress(walletId)
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .finally(function() {
    // always executed
  });

// use async approach
const nfts = await getNftsForAddress(walletId);

Get user balance for address

The getUserBalanceForAddress function allows you to get the balance of an Ethereum address in ETH. It uses the ethers library to query the Ethereum blockchain for the given address's balance.

Example:

import { getUserBalanceForAddress } from 'blockloyal-library';

getUserBalanceForAddress(walletId)
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .finally(function() {
    // always executed
  });

// use async approach
const nfts = await getUserBalanceForAddress(walletId);

Get Loyalty Program for NFT

The getLoyaltyProgramForNft function allows you to get the loyalty program information for a given non-fungible token (NFT). It makes an HTTP request to BlockLoyal's server to retrieve the information.

Example:

import { getLoyaltyProgramForNft } from 'blockloyal-library';

// Get blockloyal's loyalty program associated with NFT
getLoyaltyProgramForNft(nftId)
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .finally(function() {
    // always executed
  });

// use async approach
const nfts = await getUserBalanceForAddress(nftId);

useWallet

The useWallet hook allows a React component to interact with a user's Ethereum wallet. It provides functions for connecting to the wallet, getting the user's address, and getting the user's balance.

To use the useWallet hook, import it into your React component and call it to get an object with the following properties:

  • connect: a function that attempts to connect to the user's Ethereum wallet. If successful, it sets the user's address in the hook's state.
  • address: the user's Ethereum address, or null if the user is not connected to a wallet.
  • getUserBalance: a function that returns a promise that resolves to the user's Ethereum balance, in ETH.
  • errorMessage: a string containing an error message, if an error occurred while attempting to connect to the wallet.

Example:

import React, { useState, useEffect } from 'react';
import { useWallet } from 'blockloyal-library';

const MyComponent = () => {
  const { connect, address, getUserBalance, errorMessage } = useWallet();

  useEffect(() => {
    connect();
  }, []);

  useEffect(() => {
    if (address) {
      getUserBalance().then(balance => {
        // Update the component's state with the user's balance
        setBalance(balance);
      });
    }
  }, [address]);

  return (
    <div>
      {errorMessage && <p>{errorMessage}</p>}
      {address && <p>Your Ethereum address: {address}</p>}
      {balance && <p>Your Ethereum balance: {balance} ETH</p>}
    </div>
  );
};

Add points on NFT

The addLoyaltyPointsForNftPostPurchase functions allows the addition of post-purchase points on a given NFT. It makes an HTTP PUT request to BlockLoyal's server to register the transaction and returns an updated NFT.

Example:

import { addLoyaltyPointsForNftPostPurchase } from 'blockloyal-library';

// add points on post purchase
addLoyaltyPointsForNftPostPurchase(nftId, usdSpent)
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .finally(function() {
    // always executed
  });

// use async approach
const nft = await addLoyaltyPointsForNftPostPurchase(nftId, usdSpent);

CDN library

Get NFTs for address

The getNftsForAddress function allows you to get an array of non-fungible tokens (NFTs) that are owned by a given Ethereum address. It uses the Alchemy SDK to query the Ethereum blockchain for NFTs on the BlockLoyal contract.

Example:

const nftsData = await window.blockloyal.getNftsForAddress(walletId);

Get user balance for address

The getUserBalanceForAddress function allows you to get the balance of an Ethereum address in ETH. It uses the ethers library to query the Ethereum blockchain for the given address's balance.

Example:

const userBalance = await window.blockloyal.getUserBalanceForAddress(walletId);

Get Loyalty Program for NFT

The getLoyaltyProgramForNft function allows you to get the loyalty program information for a given non-fungible token (NFT). It makes an HTTP request to BlockLoyal's server to retrieve the information.

Example:

const loyaltyProgram = await window.blockloyal.getLoyaltyProgramForNft(nftId);

Add points on NFT

The addLoyaltyPointsForNftPostPurchase functions allows the addition of post-purchase points on a given NFT. It makes an HTTP PUT request to BlockLoyal's server to register the transaction and returns an updated NFT.

Example:

const nft = await window.blockloyal.addLoyaltyPointsForNftPostPurchase(
  nftId,
  usdSpent
);

Note async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.

License

MIT