Interactive Modal Integration

Integration guidelines for NFT Checkout feature

Prerequisite

The platform needs to create at least one Tweed account in order to communicate with the backend. Creating a Tweed account can be done using the sdk.wallet.create() function with userId and userEmail, once a user was created successfully - use the same user to use the Tokens checkout product.

Frontend Integration

The frontend part is very easy to integrate, simply call the function: sdk.token.buyWithFiat("TOKEN_ID", "WALLET_ADDRESS"), it will cause the getTokenPurchaseData callback on the backend to fire with the tokenId parameter pre populated by the frontend, you can use the tokenId to know which token the user wanted to purchase and run logic accordingly. The wallet address parameter will try to populate the argument toWalletAddress in the abi string in the backend, in the absence of this argument in the frontend the wallet address of the user will be used to populate it,

Backend Integration

During the setup of the backend SDK, the platform supplies a callback function getTokenPurchaseData that gets an tokenId and returns an TOKEN_INFO object.

Setting up the backend SDK:

const tweed = await TweedBackendSDK.setup({
  apiKey: 'YOUR_TWEED_API_KEY',
  apiSecret: 'YOUR_TWEED_API_SECRET',
  callbacks: {
    getNftPurchaseData: async ({nftId, data}),
    getTokenPurchaseData: async ({tokenId, data})
  },
  defaultBlockchainIds: ['polygonMumbai'],
})

The platform should implement the following callback function:

function getTokenPurchaseData(tokenId) {
    return TOKEN_INFO_OBJECT;
}

TOKEN_INFO object

This object is where you specify all of your Token's information, including pricing.

Specify whether you want to be paid out in fiat or in crypto in the NFT_INFO object.

You must fill out either priceInCrypto or priceInCents for each Token.

You can only be paid out in crypto or in fiat for each Token, not a combination of both for each Token. You can, however, have a mixture of Tokens paid out in crypto and Tokens paid out in fiat. See Payout Setup for more details.

export type NftPurchaseBackendPayload = {
    priceInCents?: number;         //Will be shown to the user + calculated fees
    priceInCrypto?: string;        //Will be converted to fiat and shown to the user in USD
    tokenContractAddress?: string; //For settlement in ERC20 tokens
    description: string;           //The description of the token
    contractAddress: string;       //The address of the token
    chain: string;                 //The chain where the token lives on
    fiatCurrencyId: string;        
    nftId: string;                 //The ID of the Token, this is not the on chain NFTID 
    tokenUri: string;              //The thumbnail of the Token
    title: string;                 //The title of the Token
    abi: string | Record<string, any> | Array<Record<string, any>>; //How the mint function looks like, can be a string or and actual ABI JSON
    customMintParams?: Record<string, any>; //A JSON with the actual oarameters that will get passed to the contract
};

Smart Contract Prerequisites

We don't have any limitations on how your contract looks or how many arguments your mint function uses.

There are only two prerequisites:

  1. Our claimer needs to have a minter role in the contract.

  2. In case you want to get settled in native crypto currency, the mint function needs to be payable.

The abi parameter should contain the name of the function and its arguments declerations, similar to the following example: safeMint(sendTo address, tokenId uint256, tokenUri string). The arguments needs to get populated into thecustomMintParams object like so:

customMintParams : {
    sendTo: <THE_WALLET_ADDRESS_VAR>,
    tokenId: <YOUR_TOKEN_ID_VAR>,
    tokenUri: <YOUR_TOKEN_URI_VAR>
}

Tezos integration consideration

  1. In the abi parameter of the NFT_INFO only the function name is needed without the list of params

  2. The customMintParams parameter will hold the list of arguments the function in the abi gets and translate them to their michelson representation

  3. For ex:

abi: "buy_nft"
customMintParams: {
    wallet_address: <WALLET_ADDRESS>,
    nft_uri: <NFT_URI>
}


Last updated