Using the NFT Catalog, you can generate common scripts and transactions to be run against the Flow Blockchain to support your application.
1npm install @onflow/fcl2npm install flow-catalog
or
1yarn add @onflow/fcl2yarn add flow-catalog
1. Retrieve a list of transactions available for code generation:
NOTE: In order to properly bootstrap the method, you will need to run and await
on the getAddressMaps()
method, passing it into all of the methods as shown below.
1import { getAddressMaps, scripts } from "flow-catalog";2import * as fcl from "@onflow/fcl"34const main = async () => {5const addressMap = await getAddressMaps();6console.log(await scripts.getSupportedGeneratedTransactions(addressMap));7};89main();
2. Provide a Catalog collection identifier to generate code
1const getTemplatedTransactionCode = async function() {2const catalogAddressMap = await getAddressMaps()3const result = await cadence.scripts.genTx({45/*6'CollectionInitialization' is one of the available transactions from step 1.7'Flunks' is the collection identifier in this case8'Flow' is a fungible token identifier (if applicable to the transaction being used)9*/1011args: ['CollectionInitialization', 'Flunks', 'flow'],12addressMap: catalogAddressMap13})14return result15}
3. Use the generated code in a transaction
1const txId = await fcl.mutate({2cadence: await getTemplatedTransactionCode()[0],3limit: 9999,4args: (arg: any, t: any) => []5});6const transaction = await fcl.tx(txId).onceSealed()7return transaction
Cadence scripts and transactions can be generated directly on-chain via scripts. You will need to be able to run cadence scripts to continue.
1. Retrieve a list of transactions available for code generation
Run the following script to retrieve available code generation methods: https://github.com/dapperlabs/nft-catalog/blob/main/cadence/scripts/get_supported_generated_transactions.cdc
2. Provide a catalog collection identifier to generate code
You may use the following script to generate code: https://github.com/dapperlabs/nft-catalog/blob/main/cadence/scripts/gen_tx.cdc
For example, from the CLI this may be run like the following:
flow -n mainnet scripts execute ./get_tx.cdc CollectionInitialization Flunks flow
In the above example, CollectionInitialization
is one of the supported transactions returned from step 1, Flunks
is the name of an entry on the catalog (https://www.flow-nft-catalog.com/catalog/mainnet/Flunks), and flow
is a fungible token identifier.