This project is a starting point for you to develop smart contracts on the Flow Blockchain. It comes with example contracts, scripts, transactions, and tests to help you get started.
Here are some essential resources to help you hit the ground running:
- Flow Documentation - The official Flow Documentation is a great starting point to start learning about about building on Flow.
- Cadence Documentation - Cadence is the native language for the Flow Blockchain. It is a resource-oriented programming language that is designed for developing smart contracts. The documentation is a great place to start learning about the language.
- Visual Studio Code and the Cadence Extension - It is recommended to use the Visual Studio Code IDE with the Cadence extension installed. This will provide syntax highlighting, code completion, and other features to support Cadence development.
- Flow Clients - There are clients available in multiple languages to interact with the Flow Blockchain. You can use these clients to interact with your smart contracts, run transactions, and query data from the network.
- Block Explorers - Block explorers are tools that allow you to explore on-chain data. You can use them to view transactions, accounts, events, and other information. Flowser is a powerful block explorer for local development on the Flow Emulator.
Your project has been set up with the following structure:
-
flow.json- This is the configuration file for your project (analogous to apackage.jsonfile for NPM). It has been initialized with a basic configuration and your selected Core Contract dependencies to get started.Your project has also been configured with the following dependencies. You can add more dependencies using the
flow deps addcommand:FlowServiceAccountFungibleTokenViewResolverBurnerFlowTokenMetadataViewsNonFungibleTokenFungibleTokenMetadataViewsFlowFeesFlowStorageFeesFlowExecutionParametersNodeVersionBeaconRandomBeaconHistoryFungibleTokenSwitchboardEVM
-
/cadence- This is where your Cadence smart contracts code lives
Inside the cadence folder you will find:
/contracts- This folder contains your Cadence contracts (these are deployed to the network and contain the business logic for your application)Counter.cdc
/scripts- This folder contains your Cadence scripts (read-only operations)GetCounter.cdc
/transactions- This folder contains your Cadence transactions (state-changing operations)IncrementCounter.cdc
/tests- This folder contains your Cadence tests (integration tests for your contracts, scripts, and transactions to verify they behave as expected)Counter_test.cdc
To run the GetCounter script, use the following command:
flow scripts execute cadence/scripts/GetCounter.cdcTo run the IncrementCounter transaction, use the following command:
flow transactions send cadence/transactions/IncrementCounter.cdcTo learn more about using the CLI, check out the Flow CLI Documentation.
To add a new contract to your project, run the following command:
flow generate contractThis command will create a new contract file and add it to the flow.json configuration file.
To add a new script to your project, run the following command:
flow generate scriptThis command will create a new script file. Scripts are used to read data from the blockchain and do not modify state (i.e. get the current balance of an account, get a user's NFTs, etc).
You can import any of your own contracts or installed dependencies in your script file using the import keyword. For example:
import "Counter"To add a new transaction to your project you can use the following command:
flow generate transactionThis command will create a new transaction file. Transactions are used to modify the state of the blockchain (i.e purchase an NFT, transfer tokens, etc).
You can import any dependencies as you would in a script file.
To add a new test to your project you can use the following command:
flow generate testThis command will create a new test file. Tests are used to verify that your contracts, scripts, and transactions are working as expected.
If you want to use external contract dependencies (such as NonFungibleToken, FlowToken, FungibleToken, etc.) you can install them using Flow CLI Dependency Manager.
For example, to install the NonFungibleToken contract you can use the following command:
flow deps add mainnet://1d7e57aa55817448.NonFungibleTokenContracts can be found using ContractBrowser, but be sure to verify the authenticity before using third-party contracts in your project.
To verify that your project is working as expected you can run the tests using the following command:
flow testThis command will run all tests with the _test.cdc suffix (these can be found in the cadence/tests folder). You can add more tests here using the flow generate test command (or by creating them manually).
To learn more about testing in Cadence, check out the Cadence Test Framework Documentation.
To deploy your project to the Flow network, you must first have a Flow account and have configured your deployment targets in the flow.json configuration file.
You can create a new Flow account using the following command:
flow accounts createLearn more about setting up deployment targets in the Flow CLI documentation.
To deploy your project to the Flow Emulator, start the emulator using the following command:
flow emulator --startTo deploy your project, run the following command:
flow project deploy --network=emulatorThis command will start the Flow Emulator and deploy your project to it. You can now interact with your project using the Flow CLI or alternate client.
To deploy your project to Flow Testnet you can use the following command:
flow project deploy --network=testnetThis command will deploy your project to Flow Testnet. You can now interact with your project on this network using the Flow CLI or any other Flow client.
To deploy your project to Flow Mainnet you can use the following command:
flow project deploy --network=mainnetThis command will deploy your project to Flow Mainnet. You can now interact with your project using the Flow CLI or alternate client.