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.
- 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 returingundefined
as the actionResponse from Decent is empty.
The route from Polygon to Zora is not configured in the Decent API.
-
Clone the repo
git clone https://github.com/0xnogo/nft-openAction-kit.git
-
Install NPM packages
yarn install
-
Build
yarn build
The package is not published. To use is locally, run
yarn link
in the root directory andyarn link nft-openaction-kit
in the project you want to use it.
-
Create a .env file in the root directory and add the following variables:
DECENT_API_KEY=api-key
-
Use
detectAndReturnCalldata
const fetchCalldata = async () => {
try {
const result = await detectAndReturnCalldata(url);
console.log(result || "No calldata found");
} catch (err) {
console.log(err);
}
};
- Use
actionDataFromPost
const post: PostCreatedEventFormatted = {
args: {
actionModulesInitReturnDatas: [""],
postParams: {
profileId: "48935",
contentURI:
"https://zora.co/collect/base:0x751362d366f66ecb70bf67e0d941daa7e34635f5/0",
actionModules: ["0x99Cd5A6e51C85CCc63BeC61A177003A551953628"],
actionModulesInitDatas: [calldata],
referenceModule: "0x0000000000000000000000000000000000000000",
referenceModuleInitData: "0x01",
},
pubId: "10",
referenceModuleInitReturnData: "0x",
timestamp: "1704816612",
transactionExecutor: "0x755bdaE53b234C6D1b7Be9cE7F316CF8f03F2533",
},
blockNumber: "52127727",
transactionHash:
"0x95f6175eb48fb4da576268e5dfa0ffd2f54619abdd367d65c99b2009b9f62331",
};
try {
// Call the async function and pass the link
const result: ResultData = await actionDataFromPost(
post,
profileId,
senderAddress,
srcChainId,
apiKey
);
} catch (error) {
console.log(error);
}
The
actionDataFromPost
function is accepting as input a PostCreatedEventFormatted object (as defined in https://github.com/wkantaros/lens-openAction). Another interface could be defined if needed (as long as it has the required fields).
- Modify the NFT_PLATFORM_CONFIG object in
src/platform/nftPlatform.ts
and add the new platform config follwing the type:
type NFTPlatform = {
platformName: string;
platformLogoUrl: string;
urlPattern: RegExp;
urlExtractor: (url: string) => NFTExtraction | undefined;
platformService: PlatformServiceConstructor;
};
- Create a new file in
src/platform
and add the platform service class. The class should implement theIPlatformService
interface.
export interface IPlatformService {
getMintSignature(nftDetails: NFTExtraction): Promise<string | undefined>;
getUIData(
signature: string,
contract: string,
tokenId: bigint
): Promise<UIData | undefined>;
getPrice(
contractAddress: string,
nftId: bigint,
signature: string,
unit?: bigint
): Promise<bigint | undefined>;
getArgs(tokenId: bigint, senderAddress: string, signature: string): any[];
}