Crypto Candy is an example of a full-stack dapp built on Flow blockchain using Svelte.
This project aims to introduce core concepts of Flow blockchain development and demonstrate how to use Flow Client Library (FCL) to build a decentralized app.
In this project, we will go through
- Authentication using Flow wallet.
- Use Cadence scripts to read data from the blockchain.
- Use Cadence transactions to write data to the blockchain.
- Clone the project
https://github.com/amitkothari/crypto-candy.git
- Install dependencies
npm install
- Run the app
npm run start
- Run unit tests
npm run test
These tests are implemented using jest and svelte-testing-library.
- Run contract tests
npm run test:contract
Cadence scripts and transactions are tested using flow-js-testing library.
- Run end to end tests
npm run cypress:e2e
The app uses cypress for end-to-end tests.
Flow smart contracts are implemented using Cadence which is a resource-oriented programming language.
Our contract, scripts, and transactions are under the cadence
folder.
In our CandyContract.cdc
, Candy
and Variety
are defined as cadence resources. Contract admin can add candy varieties and users can mint candies and store their collection on the blockchain.
Application's web frontend is implemented using svelte, tailwind ,and webpack.
For local development, we can deploy our contract to the Flow emulator by running the following command -
flow project deploy --network emulator
To deploy a contract to Flow Testnet, we first need a testnet account.
- Generate a key pair
flow keys generate
- Create and fund an account on testnet
Go to Flow Testnet Faucet and create a new account using the public key generated in the previous step.
- Run the following command to deploy our contract
flow project deploy --network testnet
New candy varieties can be created by using Flow transactions.
We can use Flow CLI to
- Build a transaction.
- Sign the transaction with each account specified in the build step.
- Submit the signed transaction to the Flow network.
For example, to create a new candy Lemon candy
with price 12.00
FUSD.
Run the following commands
flow transactions build ./cadence/transactions/CreateVariety.cdc "Lemon candy" "12.00" --authorizer testnet-account --proposer testnet-account --payer testnet-account -n Testnet--filter payload --save built.rlp
flow transactions sign ./built.rlp --signer testnet-account -n Testnet--filter payload --save signed.rlp -y
flow transactions send-signed ./signed.rlp -n testnet
Please refer to the docs for more details.
- If you get an error
gRPC requires HTTP/2
or are unable to run the contract tests, please make sure that the emulator is not already running.
This project is heavy inspired by crypto dappy.