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

nft-openaction-kit

v1.0.35

Published

Seamless integration of NFT platforms into the Lens protocol by enabling automatic detection and handling of NFT links within Lens publications.

Downloads

1,466

Readme

nft-openaction-kit

Description

The nft-openaction-kit package simplifies the process of integrating an NFT minting open action into Lens applications. This package has two core functionalities:

When a user posts a link to an NFT in a Lens Publication, this package will parse data from the URL and smart contracts to embed an NFT minting open action into the Lens Publication.

When a post appears in a Lens application feed with the NFT minting action attached, the app can use this package to populate metadata to appear on a UI and generate calldata to perform the transaction.

Supported Collections

Zora

What is suported

  • Any NFT that is actively minting and is priced in ETH

What is not currently supported

  • NFTs that are priced in other ERC20 tokens are not currently supported
  • If an NFT page is listed as "secondary" this means it is no longer a primary mint and is not currently supported

Pods Media

  • Any NFT that is actively minting

Features

  • Function 1: detectAndReturnCalldata. Detects the NFT platform and returns the calldata to be used in the post action.
  • Function 2: actionDataFromPost. Returns the encoded calldata from Decent and UI data for the post action.
  • Extensible: the kit is extensible to add new NFT platforms with the usage of IPlatformService interface.
  • Zora detection logic: detect collections with an active sale (ZoraCreatorFixedPriceSaleStrategy for ERC1155 or contract collection for ERC721). All other cases are discarded as they don't represent a minting event (require specific handling - e.g. Seaport integration).

actionDataFromPost is returing undefined as the actionResponse from Decent is empty.

The route from Polygon to Zora is not configured in the Decent API.

Installation

  1. Clone the repo

    git clone https://github.com/0xnogo/nft-openAction-kit.git
  2. Install NPM packages

    yarn install
  3. Build

    yarn build

Usage

The package is not published. To use is locally, run yarn link in the root directory and yarn link nft-openaction-kit in the project you want to use it.

  1. Create a .env file in the root directory and add the following variables:

    DECENT_API_KEY=api-key
  2. Instantiate the NFTOpenActionKit class and use the detectAndReturnCalldata and actionDataFromPost methods.

import { NftOpenActionKit } from "nft-openaction-kit";

// @param decentApiKey - string, required decent.xyz API key
// @param option fallbackRpcs - mapping of chainId to fallback RPC url
const nftOpenActionKit = new NftOpenActionKit({
  decentApiKey: process.env.DECENT_API_KEY,
  fallbackRpcs: {
    [7777777]: "https://zora.g.alchemy.com/v2/<apiKey>",
    [8453]: "https://base.g.alchemy.com/v2/<apiKey>",
  },
});
  1. When a Lens publication is created, the detectAndReturnCalldata method can be used by passing a URL, it will be parsed and if a supported NFT link is found the response type is a string containing the open action calldata to be included within the post, comment, quote, or mirror transaction.

Example Usage

const fetchCalldata = async () => {
  try {
    const result = await nftOpenActionKit.detectAndReturnCalldata({
      contentURI: url, // url string to parse NFT data from
      publishingClientProfileId: "10", // profileId, the owner address of this profile receives frontend mint rewards
    });
    console.log(result || "No calldata found");
  } catch (err) {
    console.log(err);
  }
};
  1. Use actionDataFromPost when a publicaiton is rendered on a Lens feed to generate the cross-chain transaction calldata to be included with the act transaction.

Example Usage

const publication = {
  profileId: "48935",
  actionModules: ["0x99Cd5A6e51C85CCc63BeC61A177003A551953628"],
  actionModulesInitDatas: [calldata],
  pubId: "10",
};

try {
  // Call the async function and pass the link
  const result: ActionData = await nftOpenActionKit.actionDataFromPost({
    post: publication,
    profileId,
    profileOwnerAddress,
    senderAddress,
    srcChainId,
    quantity,
    paymentToken,
    executingClientProfileId,
    mirrorerProfileId,
    mirrorPubId,
    sourceUrl,
  });
} catch (error) {
  console.log(error);
}

The actionDataFromPost function is accepting a subset of fields from Publication events (example event defined in https://github.com/wkantaros/lens-openAction).

Display UI Elements

The actionDataFromPost or generateUIData functions return a uiData property. This object contains NFT metadata that can be used on a frontend display. All available properties are detailed below:

type UIData = {
  platformName: string;
  platformLogoUrl: string;
  nftName: string;
  nftUri: string;
  nftCreatorAddress?: string;
  tokenStandard: string;
  dstChainId: number;
  rawMetadataUri?: string;
  zoraAdditional?: ZoraAdditional;
  podsAdditional?: PodsAdditional;
};

type ZoraAdditional = {
  name?: string;
  description?: string;
  image?: string;
  animation_url?: string; // video or audio field, if one exists
  content?: {
    mime?: string;
    uri?: string;
  };
};

export type PodsAdditional = {
  animation_url?: string; // podcast audio file
  artwork?: {
    kind?: string;
    type?: string;
    uri?: string;
  };
  collection?: string;
  credits?: {
    name?: string;
    role?: string;
  }[];
  description?: string;
  episodeNumber?: number;
  episodeTitle?: string;
  external_url?: string;
  image?: string;
  name?: string;
  podcast?: string;
  primaryMedia?: {
    kind?: string;
    type?: string;
    uri?: string;
    duration?: number;
  };
  properties?: {
    Collection?: string;
    Podcast?: string;
    guest_1?: Record<string, unknown>;
    host_1?: Record<string, unknown>;
    host_2?: Record<string, unknown>;
    [key: string]: unknown;
  };
  publishedAt?: string;
  version?: string;
};

Add a new NFT platform

  1. If an api is required, modify the SdkConfig type in src/types/index.ts:
type SdkConfig = {
  decentApiKey: string,
  raribleApiKey?: string,
  openSeaApiKey?: string,
};
  1. Modify the initializePlatformConfig function in src/DetectionEngine.ts and add the new platform config following the type:
type NFTPlatform = {
  platformName: string,
  platformLogoUrl: string,
  urlPattern: RegExp,
  urlExtractor: (url: string) => Promise<NFTExtraction | undefined>,
  platformService: PlatformServiceConstructor,
};
  1. Create a new file in src/platform and add the platform service class. The class should implement the IPlatformService interface.
export type NFTPlatform = {
  platformName: string,
  platformLogoUrl: string,
  urlPattern: RegExp,
  urlExtractor: (url: string) => Promise<NFTExtraction | undefined>,
  platformService: PlatformServiceConstructor,
  apiKey?: string,
};

If an api key is required, make sure to add it in the DetectionEngine class and handle it in the initializePlatformConfig function. The Rareble detection is an example of how to handle an api key.

  1. Create a new file in src/platform and add the platform service class. The class should implement the IPlatformService interface.
interface IPlatformService {
  platformName: string;
  getMinterAddress(
    nftDetails: NFTExtraction,
    mintSignature: string
  ): Promise<string>;
  getMintSignature(
    nftDetails: NFTExtraction,
    ignoreValidSale?: boolean
  ): Promise<string | undefined>;
  getUIData(
    signature: string,
    contract: string,
    tokenId: bigint,
    dstChainId: bigint,
    sourceUrl?: string
  ): Promise<UIData | undefined>;
  getPrice(
    contractAddress: string,
    nftId: bigint,
    signature: string,
    userAddress: string,
    unit?: bigint,
    sourceUrl?: string
  ): Promise<bigint | undefined>;
  getArgs(
    contractAddress: string,
    tokenId: bigint,
    senderAddress: string,
    signature: string,
    price: bigint,
    quantity: bigint,
    profileOwnerAddress: string,
    sourceUrl?: string
  ): Promise<any[]>;
}