*** title: How to Generate Calldata for NFT Checkout slug: guides/how-to-generate-calldata-for-nft-checkout subtitle: Generate the smart contract call data required for Transak NFT Checkout --------------------------------------------------------------------------------- ## What is calldata? `Calldata` is the encoded hex data for the smart contract function that Transak will execute during NFT Checkout. It tells the contract: * which function to call * which arguments to pass * the exact order and format of those arguments For NFT Checkout, you generate this calldata from your contract ABI and function inputs, then pass it to Transak as the `calldata` parameter. ## Prerequisite: Partner setup before you start Before you generate calldata, make sure you already have: * The ABI for the contract function that should be executed * The exact `function name` * The exact `arguments in the correct order` * The Transak NFT Checkout smart contract address for the target chain if your function accepts a recipient wallet address such as `to`, `recipient`, or `buyer`
If you use a proxy contract, encode the calldata with the ABI of the **implementation contract**, `not the proxy`.
If your function accepts a wallet parameter such as `to`, `recipient`, or `buyer`, pass Transak's NFT Checkout smart contract address for that chain instead of the end user's wallet address.
Use [NFT Checkout smart contract addresses](/products/nft-checkout#transak-smart-contract-addresses) to get the correct chain-specific address. ## How to generate calldata ```javascript const getSupplyCalldata = (contributor: string, amount: number | null) => { if (!amount) return; /** * ABI for Supply function on AAVE SmartContract * You can find ABI of AAVE contract here: * https://mumbai.polygonscan.com/address/0xbadd48c3eb42a10db791d7b02e3c07fbf95b3155#code */ let ABI = [ { inputs: [ { internalType: "contract IPoolAddressesProvider", name: "provider", type: "address", }, ], stateMutability: "nonpayable", type: "constructor", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "reserve", type: "address", }, { indexed: true, internalType: "address", name: "backer", type: "address", }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256", }, { indexed: false, internalType: "uint256", name: "fee", type: "uint256", }, ], name: "BackUnbacked", type: "event", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "reserve", type: "address", }, { indexed: false, internalType: "address", name: "user", type: "address", }, // ABI shortened here for practical purposes ], name: "BalanceTransfer", type: "event", }, ]; }; ``` ```typescript let parsedAmmount = parseUnits(amount.toString(), 8); // Constructing the CallData return new Interface(ABI).encodeFunctionData("supply", [ "0x2Fa2e7a6dEB7bb51B625336DBe1dA23511914a8A", // asset contract address for WBTC as an example on mumbai testnet parsedAmmount, // amount user wants to buy contributor, // address of the user who is depositing the funds 0, // referal code. Will be 0 in case of aave ]); ``` ```typescript export default function App() { useEffect(() => { const depositAmount = 0.0008; // amount user want to deposit to protocol const calldata = getSupplyCalldata( USER_WALLET_ADDRESS, // user wallet address depositAmount // amount user want to deposit. Transak will convert it to the fiat equivalent and display it to the user ); } } ``` If you are passing calldata through a widget URL or through `createWidgetUrl`, pass the raw hex string directly as the `calldata` value. ```bash title="Create Widget URL" curl --request POST \ --url https://api-gateway-stg.transak.com/api/v2/auth/session \ --header 'accept: application/json' \ --header 'access-token: YOUR_ACCESS_TOKEN' \ --header 'content-type: application/json' \ --data '{ "widgetParams": { "apiKey": "API_KEY", "walletAddress": "USER_WALLET_ADDRESS", "isNFT": true, "calldata": "0xsdad....", "nftData": [ { imageURL: "https://pokemon-nfts.s3.ap-southeast-2.amazonaws.com/images/1.png", // string nftName: "Pokemon Metadata Legends", // string collectionAddress: "0x8a20e9e8e736643161ce6a2fe8dd8dd62050cd1e", // string tokenID: ["6", "7", "8"], // string[] price: [15, 15, 15], // number[] quantity: 3, // number nftType: "ERC721" // "ERC721" | "ERC1155" } ], "contractId": "6965438baf941bf38cd", } ``` If you use the [SDK](/integration/web/js-sdk), pass the raw calldata directly in the SDK configuration. ## Full Example To Generate Calldata ```javascript const getSupplyCalldata = (contributor: string, amount: number | null) => { if (!amount) return; /** * ABI for Supply function on AAVE SmartContract * You can find ABI of AAVE contract here: * https://mumbai.polygonscan.com/address/0xbadd48c3eb42a10db791d7b02e3c07fbf95b3155#code */ let ABI = [ { inputs: [ { internalType: "contract IPoolAddressesProvider", name: "provider", type: "address", }, ], stateMutability: "nonpayable", type: "constructor", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "reserve", type: "address", }, { indexed: true, internalType: "address", name: "backer", type: "address", }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256", }, { indexed: false, internalType: "uint256", name: "fee", type: "uint256", }, ], name: "BackUnbacked", type: "event", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "reserve", type: "address", }, { indexed: false, internalType: "address", name: "user", type: "address", }, // ABI shortened here for practical purposes ], name: "BalanceTransfer", type: "event", }, ]; let parsedAmount = parseUnits(amount.toString(), 8); return new Interface(ABI).encodeFunctionData("supply", [ "0x2Fa2e7a6dEB7bb51B625336DBe1dA23511914a8A", // asset contract address for WBTC on Mumbai testnet parsedAmount, // amount user wants to buy contributor, // address of the user who is depositing the funds 0, // referral code. Will be 0 in case of AAVE ]); }; // Create Widget URL API const calldata = getSupplyCalldata(USER_WALLET_ADDRESS, 0.0008); console.log("Use this in the SDK config:", calldata); console.log( "Or pass it in the widget URL:", `"widgetParams": { calldata: ${calldata} }` ); ```