Welcome to your new Flow NFT project. We provided you with an example to get started. The ExampleNFT
contract is taken from https://github.com/onflow/flow-nft
Getting started can feel overwhelming, but we are here for you. Depending on how accustomed you are to Flow here's a list of resources you might find useful:
- Cadence documentation: here you will find language reference for Cadence, which will be the language in which you develop your smart contracts,
- Visual Studio Code and Cadence extension: we suggest using Visual Studio Code IDE for writing Cadence with the Cadence extension installed, that will give you nice syntax highlitning and additional smart features,
- SDKs: here you will find a list of SDKs you can use to ease the interaction with Flow network (sending transactions, fetching accounts etc),
- Tools: development tools you can use to make your development easier, Flowser can be super handy to see what's going on the blockchain while you develop
NFT Resources:
- flow-nft: home of the Flow NFT standards, contains utility contracts, examples, and documentation,
- nft-storefront: NFT Storefront is an open marketplace contract used by most Flow NFT marketplaces,
- Flow NFT Catalog: list of NFT contracts on Flow, can be a valuable source to compose new projects or use as example,
Your project comes with some standard folders which have a special purpose:
/cadence
inside here is where your Cadence smart contracts code livesflow.json
configuration file for your project, you can think of it as package.json, but you don't need to worry, flow dev command will configure it for you
Inside cadence
folder you will find:
/contracts
location for Cadence contracts go in this folder/scripts
location for Cadence scripts goes here/transactions
location for Cadence transactions goes in this folder
After creating this project using the flow setup command you should then start the emulator by running:
> flow emulator --contracts
we use --contracts
flag to include more already deployed contract we can then easily import in our project.
and then start the development command by running:
> flow dev
After the command is started it will automatically watch any changes you make to Cadence files and make sure to continiously sync those changes on the emulator network. If you make any mistakes it will report the errors as well. Read more about the command here
Using external dependencies
If you wanna use external contract dependencies (like NonFungibleToken, FlowToken, FungibleToken,..) you can install them using Cadence dependency manager: https://developers.flow.com/tools/flow-cli/dependency-manager
Use ContractBrowser to explore available 3rd party contracts in the Flow ecosystem.
First, we need to create a new test account for the emulator. Let's call it user1
:
flow accounts create
Initialize the user1
account:
flow transactions send \
cadence/transactions/init.cdc \
--signer user1
user1
Account can now store and receive ExampleNFT
.
With user1
account initialized to receive ExampleNFT
, we can now mint into the user1
account. The minting transaction should be signed by the account that's storing the ExampleNFT
contract (admin). We need to pass the recipient account's address to the mint transaction. You can grab it from the initialization step above, or flow.json
.
flow transactions send \
cadence/transactions/mint.cdc \
0xe03daebed8ca0615 \
"Hello World" \
"Hello from Cadence" \
"https://example.com/my-nft-thumbnail.png" \
"[]" \
"[]" \
"[]" \
--signer exampleNFT
Fetch the id
s of ExampleNFT
NFTs stored in a given account:
flow scripts execute \
cadence/scripts/get_nft_ids.cdc \
0xUser1Address \
/public/exampleNFTCollection
Fetch metadata for given ExampleNFT
id in an account:
flow scripts execute \
cadence/scripts/get_nft_metadata.cdc \
0xUser1Address \
your_nft_id
Create and initialize another account and call it user2
:
flow accounts create
flow transactions send cadence/transactions/init.cdc --signer user2
Transfer ExampleNFT
with given nft_id
to user2
:
flow transactions send \
cadence/transactions/transfer.cdc \
your_contract_address \
ExampleNFT \
user2_address \
your_nft_id \
--signer user1
- Cadence Language Reference https://developers.flow.com/cadence/language
- Flow Smart Contract Project Development Standards https://developers.flow.com/cadence/style-guide/project-development-tips
- Cadence anti-patterns https://developers.flow.com/cadence/anti-patterns