paint-brush
Building Easy Workflows For Web3 Using Flow & Cadenceby@johnjvester
772 reads
772 reads

Building Easy Workflows For Web3 Using Flow & Cadence

by John VesterOctober 18th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Flow is optimized for digital asset creation and management on the Flow blockchain. Its smart contract language, Cadence, improves upon other languages’ pitfalls through its resource-based approach and a strong, static type system. In this article, we take a look at the essential tools smart contract developers can use to make building on Flow easier. We’ll also contrast these to tools you may already be familiar with, such as CLIs, IDE extensions, client libraries, local networks, and more.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Building Easy Workflows For Web3 Using Flow & Cadence
John Vester HackerNoon profile picture

Smart contract development is no different than other types of software development. Code is written to perform a certain task, and there are tools that help make this process easier. The Ethereum ecosystem contains many mature tools to help build Web3 projects, but what about a newer ecosystem, such as Flow?


If you’ve been following along with this series so far, you’ll know that the Flow blockchain is optimized for digital asset creation and management. Additionally, its smart contract language, Cadence, improves upon other languages’ pitfalls through its resource-based approach and a strong, static type system.


In this article, we’ll take a look at the essential tools smart contract developers can use to make building on Flow easier—tools such as CLIs, IDE extensions, client libraries, local networks, and more. We’ll also contrast these to Ethereum tools you may already be familiar with, so if you’re making the switch to Flow, you’ll know exactly what to expect.

Command-line Interfaces

Command-line interfaces (CLI) are the bread and butter of software development. They are intuitive for most developers and integrate easily with other software.

This easy integration applies to smart contract development as well. For example, if you need to quickly deploy a contract to test it or run it with different accounts, a CLI can help immensely. And later, when you want to add the deployment process to a CI/CD pipeline, you’ll be happy to have a simple CLI tool you can automate with shell scripts.


On EVM-compatible networks like Ethereum, Truffle and Hardhat both offer powerful tools for these tasks. The Hardhat Runner is used for almost all actions with Hardhat, while the __Truffle Console__enables developers to quickly interact with their smart contracts via JavaScript without having to write script files.

The Flow CLI is the primary tool for developing, testing, and deploying smart contracts written in Cadence to the Flow network. In addition, it’s the interface you use when interacting with the Flow blockchain, such as creating and checking accounts, signing transactions, or automating tasks with scripts.


Unlike Ethereum, where you would generate an address to interact with the blockchain, Flow requires you to have an account. This account holds your smart contracts, tokens, and keys, and is necessary for interacting with the blockchain. You can easily create accounts using the Flow CLI.




IDE Extensions

Next, you want to write some code, and languages like Cadence and Solidity offer static type checking that gives you some helpful information about how your code will behave in your editor.


While Solidity comes with a fundamental type system that prevents you from mixing different number types, Cadence goes a few steps further and introduces the concept of ownership. You might know this from Rust, but the basic idea is that Cadence has resources, like NFTs, that can only be owned by one address. A Cadence IDE extension will notify you about issues with your NFT transactions right at the point when you’re writing the code, while also offering syntax highlighting, code completion, and type checking.




Linters

You might know linters from languages like JavaScript, where no static typing is available. In this context, a linter helps to prevent common errors and to aid developers in following best practices.


The same is true for Solhint, a linter tool for Solidity. Again, Solidity’s static type system is very rudimentary and doesn’t prevent many errors while using the language. Solhint comes to aid here and provides tips on top of the type system to avoid misuse.


The Cadence language has a much more sophisticated type system and comes with more help than Solidity. A correctly typed Cadence smart contract is more secure than a correctly typed Solidity one.


The typical linter functionality is built right into the Cadence language itself through its type system, but if you want to run type checks on multiple Cadence files inside your CI/CD pipeline, the Cadence lint tool can help.

Local Networks

A local network, or a network emulator, is a tool that will run a blockchain network on your development computer, so you can test in a clean environment and not risk pushing unfinished smart contracts to a live blockchain. A local network also has lower latency and allows you to control the block creation, so you can step through everything that happens when your smart contract executes.


When developing on the EVM, you probably know and use the Hardhat Network or Ganache for this task. Both tools simulate a blockchain environment on your local machine and allow you to fork a version of mainnet to interact with real accounts and contracts.


Flow offers a similar feature called the Flow Emulator that simulates the real Flow network but gives you more options to interact with. It enables account storage limits, setting initial FLOW token supplies, and enabling persistent state between restarts. This powerful tool is used via the Flow CLI mentioned above and together, they provide all the features developers need to build fully functioning dapps and the environment to test them in.


With theFlow CLI installed, all one has to do to start the emulator is type the command flow emulator in their terminal.




Testnet Faucets

When developing smart contracts, you typically need crypto tokens to deploy and interact with your code. Otherwise, how will you test transactions?


Flow, just like Ethereum, has__a testnet__ that comes with a faucet that drips you free testnet FLOW or FUSD for development.




Additionally, Blocto Swap is a multi-use tool that makes creating an account on Flow simple for users. All one has to do is enter an email address. Blocto Swap allows users to easily exchange their tokens for different types to use in testing. This tool is also a handy way to get FUSD if that collection is not already initialized in the account.




Remember: tokens on a testnet hold no value outside of testing.

Automated Testing

Cadence and Solidity both have test automation tools that allow you to write your tests in JavaScript.


The Hardhat development tools use the Chai test runner and supply you with smart contract matchers and network helpers for the EVM.


Cadence has its own tools that use Jest as the base, but they’re framework agnostic. So if Jest isn’t your thing, you can use a different test runner.

Blockchain Explorers

Another vital part of all blockchain networks is the block explorer—a tool that allows you to check out everything that happens on-chain.


For the Ethereum network, you might know Etherscan. It’s a web application that lets you browse mainnet and testnet transactions and addresses.


Flow comes with a much more powerful tool,Flowser!





Flowser (Flow Browser) is a web application, but you can run it locally. It allows you to browse both the Flow mainnet and any local network you start with the Flow Emulator. It even comes with a GUI to configure and start an emulator and manage your development wallets.


However, if all you need to do is check transactions or browse on the Flow mainnet or testnet, then the traditional block explorer__Flowscan__ will suit your needs.




Additionally, the flow-view-source tool allows users to inspect accounts and their various attributes, such as balances, keys, and any contracts they may contain.







Interfacing with JavaScript

To build a decentralized application (dapp) for your smart contract, you need a bridge between the blockchain network and the web. Flow and Ethereum both come with Webpack integrations to solve this problem.


The Solidity Loader will automatically reload your application when you change your Solidity code, so your frontend always runs with the current version of your smart contract while in development.


Cadence offers similar features via its Webpack plugin and the Cadence utilities.


Additionally, the Flow Client Library (FCL) JS is one of the best ways for a developer to quickly start building on the Flow blockchain. This package makes interacting with wallets and smart contracts simple and secure, while providing all the tools necessary to create fully functioning dapps.

Playgrounds

Being able to test your code in environments without having to invest the time in creating an entire project enables developers to quickly figure out what works and what doesn’t. To that end, Flow has the Flow Playground. Not only is it an excellent resource to iterate through ideas quickly, it’s also a great environment to learn in, with tutorials included to teach important concepts and how to build common projects.




Although Ethereum doesn’t have any projects exactly like the Flow Playground, there are a few you could take advantage of to create a similar experience. The online Solidity code editor, Remix, provides an environment to quickly build and test smart contracts. Additionally, you could follow along with the Developer DAO Academy to help get you up to speed with Solidity and Remix.

Summary

Software development, and smart contract development in particular, is a complex process that consists of different vital steps. Planning, coding, testing, deploying, and maintenance are all important parts of the process, and having the proper tools at hand makes things easier.


Although Flow has a younger ecosystem compared to Ethereum, the tools and libraries available are mature enough to help speed up the development process. From command-line interfaces and IDE extensions to local networks and block explorers, Flow has all the tools an Ethereum developer might be expecting and more.


Additionally, the type system and built-in features of the Cadence smart contract language offer controls that Solidity can’t offer without additional tools such as linters. Even then, the value those Solidity tools delivers is inferior to the features Cadence provides natively.


Overall, the Flow ecosystem comes with all the tools you need for each step of the development lifecycle. To get started building on Flow, check out their Developer Portal. Developers are also encouraged to share their own tools with the ecosystem, contribute to already existing tools, or apply for grants to build your projects.


For a list of other great tools in the Flow ecosystem,check out this Github repo.


Have a really great day!