Flow Blockchain Integration Diagram
The NFT Kit enables users to verify ownership of non-fungible tokens (NFTs) and access related data across multiple blockchains, helping them build decentralized applications, games and more. This document outlines the integration components to make all functionality also available on Flow. The NFT Kit can be used through a REST API or as a library in Java/Kotlin.
To enable support for Flow, the NFT-Kit uses the underlaying components NFTs Operation, and Cadence Scripts. Those components are hidden from the end-user, but offer developers to extend functionality offered by the NFT-Kit for Flow when needed.
Underlying components enabling Flow
The Cadence Scripts Component: Scripts to run non-permanent Cadence snippets in a flexible and powerful way, helping the NFT-Kit retrieve data from the Flow blockchain. Cadence is the smart contract programming language used on the Flow blockchain.
NFT Operation Component: A JavaScript project that uses the Flow Client Library (FCL) to establish safe and secure interactions with the Flow blockchain. With it, the NFT-Kit can retrieve NFTs and their details from chain and perform various operations on them.
The FCL JS package enables communication between user wallets and the Flow blockchain, making it unnecessary for dapps to modify their code or integrate custom solutions when utilizing FCL for authentication. Its purpose is to simplify and secure the development of applications that interface with the Flow blockchain by providing a standardized set of communication patterns for wallets, applications, and users. Additionally, FCL JS includes an SDK and utilities to interact with the Flow blockchain, and can be used in both browser and server environments.
To use the FCL JS in your application, install using yarn or npm
Importing
ES6
Node.js
The accessNode.api
key specifies the address of a Flow access node. Flow provides these, but in the future access to Flow may be provided by other 3rd parties, through their own access nodes. discovery.wallet
is an address that points to a service that lists FCL compatible wallets. Flow's FCL Discovery service is a service that FCL wallet providers can be added to, and be made 'discoverable' to any application that uses the discovery.wallet
endpoint.
FCL enables interactions with the Flow blockchain by :
Query the chain: Send arbitrary Cadence scripts to the chain and receive back decoded values.
Mutate the chain: Send arbitrary transactions with your own signatures or via a user's wallet to perform state changes on chain.
Cadence is a programming language designed for developing smart contracts in a blockchain environment. It introduces new features to smart contract programming that help developers ensure that their code is safe, secure, clear, and approachable. Cadence utilizes a strong static type system, resource-oriented programming, built-in pre- and post-conditions for functions and transactions, and capability-based security. Its syntax is inspired by popular modern general-purpose programming languages such as Swift, Kotlin, and Rust. Cadence aims to be safe and secure, clear, approachable, and developer-friendly. It makes use of resources to intuit ownership, which is tied to the account that owns it, ensuring that assets can only exist in one location at a time and cannot be copied or lost due to a coding mistake. The language addresses challenges with existing languages, such as safety and security concerns due to the immutable nature of blockchains and the lack of support for modifying or updating smart contracts.
In the Flow blockchain, the concept of "capabilities" is used to enforce access control and ensure security. A capability is an object that represents a specific permission to access a resource, such as a smart contract or a resource stored in an account.
In Flow, capabilities are created and owned by the resource itself, and can only be passed to other accounts or contracts through a special "borrow" mechanism. This mechanism ensures that access to a resource can only be granted by the owner of the resource, and that the permission to access the resource is explicitly granted on a per-resource basis.
Capabilities are also used to limit the scope of access to a resource. For example, a capability can be created that allows read-only access to a resource, or that only allows access to a specific function or method within a resource. By limiting the scope of access in this way, capabilities help to prevent unintended or malicious access to resources and reduce the risk of attacks.
Overall, the use of capabilities in Flow provides a flexible and secure access control mechanism that is well-suited to the needs of decentralized applications and smart contracts.
NFTs are digital assets that represent ownership of a unique asset and are indivisible. Cadence, the smart contract language on Flow blockchain, represents NFTs as a resource object stored in user accounts. This ensures NFTs benefit from resource ownership rules, protecting them from accidental or malicious programming errors.
NFTs allow for the trading of assets and proving of ownership, and on Flow, NFTs are interoperable across different smart contracts and app contexts. All NFTs on Flow implement the NFT Token Standard, defining a basic set of properties.
The NonFungibleToken
contract defines the following set of functionality that must be included in each implementation.
Contracts that implement the NonFungibleToken
interface are required to implement two resource interfaces:
NFT
- A resource that describes the structure of a single NFT.
Collection
- A resource that can hold multiple NFTs of the same type.
Users typically store one collection per NFT type, saved at a well-known location in their account storage.
This function is available on the NonFungibleToken.CollectionPublic
interface, which accounts publish as public capability.
Each view represents a different type of metadata, such as an on-chain creator biography or an off-chain video clip. Views do not specify or require how to store your metadata, they only specify the format to query and return them, so projects can still be flexible with how they store their data.
The NonFungibleToken
and MetadataViews
contracts are already deployed on various networks. You can import them in your contracts from these addresses. There is no need to deploy them yourself.
Note: With the emulator, you must use the -contracts flag to deploy these contracts.
This example shows how to read basic information about an NFT including the name, description, image and owner.
The views categorized as "Core views" are deemed as the essential views that must be included to offer a comprehensive representation of an NFT. If you intend to have your NFT displayed on the Flow NFT Catalog, it is mandatory to have all of these views implemented.
The NFT Catalog is a registry that resides on the blockchain and catalogs the NFT collections available on Flow blockchain that conform to the NFT metadata standard. This enables developers of decentralized applications to conveniently develop on top of and find compatible NFT collections on Flow.
NFTCatalog.cdc
: This contract contains the NFT Catalog
NFTRetrieval.cdc
: This contract contains helper functions to make it easier to discover NFTs within accounts and from the catalog
For example, all NBA Top Shot Moments owned by a single user are held in a stored in their account at the path /storage/MomentCollection
.
Return a list of NFTs in a Collection
using the function.
NFT metadata is represented in a flexible and modular way using the .
When writing an NFT contract, you should implement the interface, which allows your NFT to implement one or more metadata types called views.
Network | Contract Address |
---|
Source:
Network | Address |
---|
Network | Address |
---|
Emulator/Canary |
|
Testnet |
|
Mainnet |
|
Mainnet | 0x49a7cda3a1eecc29 |
Testnet | 0x324c34e1c517e4db |
Mainnet | 0x49a7cda3a1eecc29 |
Testnet | 0x324c34e1c517e4db |