In this tutorial, we will learn how to use smart contracts, switch accounts, and view account state.
Cadence is a new smart contract programming language for use on the Flow Blockchain. Cadence introduces new features to smart contract programming that help developers ensure that their code is safe, secure, clear, and approachable. Some of these features are:
- Type safety and a strong static type system
- Resource-oriented programming, a new paradigm that pairs linear types with object capabilities to create a secure and declarative model for digital ownership by ensuring that resources (and their associated assets) can only exist in one location at a time, cannot be copied, and cannot be accidentally lost or deleted
- Built-in pre-conditions and post-conditions for functions and transactions
- The utilization of capability-based security, which enforces access control by requiring that access to objects is restricted to only the owner and those who have a valid reference to the object
Please see the Cadence introduction for more information about the high level design of the language.
The Flow Playground includes an in-browser editor and emulator to experiment with Flow. Using the Flow Playground, you can write Cadence smart contracts, deploy them to a local Flow emulated blockchain, and submit transactions.
The Flow Playground should be compatible with any standard web browser, but we recommend that you use Google Chrome with it, because it has been tested and optimized for only the Chrome browser so far.
The Playground contains everything you need to get familiar with deploying Cadence smart contracts and interacting with transaction and scripts.
The Playground comes pre-loaded with contract and transaction templates that correspond to each of the tutorials in the docs site. To load the contracts from a specific tutorial, click the "Examples" link at the top of the Playground. This opens up a menu with each tutorial.
When you click on one of these links, the tutorial will open in a new tab and the contracts, transactions, and scripts will be loaded into the templates in the Playground for you to use.
The Accounts section on the left side of the screen is where the active accounts are listed and selected. An account can have a smart contract deployed to it, which will be covered later. You can click on an account tab to view the contract that is associated with that account in the main editor.
When you have Cadence code open in the account editor that contains a contract, you can click the deploy button in the top-right of the screen to deploy that contract to the currently selected account.
After a few seconds, you should see a message in the console confirming that the contract was deployed. You should also see the name of the contract show up in the tab for that account, indicating the account now has that contract deployed to it.
You can also select transactions and scripts from the left selection menu and submit them to interact with your deployed smart contracts, which will be covered in the Hello World tutorial.
This is just a small set of the things you can do with the Playground. If you would like a more detailed explanation of the different Playground features, look at the Playground Manual.
Each tutorial in this package uses several files containing transactions, contracts, and scripts. All the code you need will be provided in the text of the tutorials for you to copy and paste, or you can use the pre-generated tutorial setups in the Playground.
Now that you have the Flow Developer Playground running, you can create a smart contract for Flow!