This was a project created for the first Flow Hackathon - Season 1 from February 21st to March 1st, 2023.
This dapp allows a user to purchase a Coin(NFT) for 1 $FLOW which represents either Heads or Tails, and then the user can toss it into magical waters. If the random outcome(Heads or Tails) on-chain is the same as their Coin, then the user will receive 2 $FLOW, while losing will result in the user not receiving anything. The coin is destroyed whenever it is tossed into the magical waters.
- React
- Tailwind CSS
- Flow CLI
- Graffle(Flow Events monitoring)
- Pinata(IPFS)
https://testnet.flowscan.org/account/0xf8568211504c7dcf
Use this to get started on the emulator and test the major functionality
- flow emulator start -v
- flow deploy project
- flow keys generate
- flow accounts create --key PublicKey
- update flow.json
- flow transactions send ./cadence/transactions/setup.cdc
- flow transactions send ./cadence/transactions/setup.cdc --signer=justin
- Run three times
flow transactions send ./cadence/transactions/mint_nft.cdc f8d6e0586b0a20c7 0 0 QmZrieu9iKvaSQjt9YksnkxKxghCeLPVubhAcjZovBPrio
- Run for Tokens 0,1,2
flow transactions send ./cadence/transactions/list_for_sale.cdc 0 1.0 10. Expect tokens 0,1,2 flow scripts execute ./cadence/scripts/get_nft_details.cdc f8d6e0586b0a20c7 11. Expect token 0,1,2 flow scripts execute ./cadence/scripts/get_nft_listings.cdc f8d6e0586b0a20c7 12. flow transactions send ./cadence/utilities/fundEmulator.cdc f8d6e0586b0a20c7 1000.0 13. flow transactions send ./cadence/utilities/fundEmulator.cdc 01cf0e2f2f715450 1000.0 14. flow transactions send ./cadence/transactions/purchase.cdc f8d6e0586b0a20c7 0 --signer=justin 15. Expect tokens 1,2 flow scripts execute ./cadence/scripts/get_nft_details.cdc f8d6e0586b0a20c7 16. Expect token 0 flow scripts execute ./cadence/scripts/get_nft_details.cdc 01cf0e2f2f715450 17. Run for tokens 1,2 flow transactions send ./cadence/transactions/purchase.cdc f8d6e0586b0a20c7 1 --signer=justin 18. Play game flow transactions send ./cadence/transactions/play_game.cdc 0 0xf8d6e0586b0a20c7 --signer=justin 19. Admin flips coin flow transactions send ./cadence/transactions/flip_coin.cdc 0 20. Play the game for tokens 2,3 21. Admin flips coins
-
flow keys generate
-
Enter public key: https://testnet-faucet-v2.onflow.org/
-
Store these keys safely
-
Update flow.json testnet-account with the private key and address
-
Ensure flow.json has the right contracts to be deployed
-
Update hardcoded values in scripts/txns
Hardcoded admin values
flip_coin.cdc flip_coins.cdc coinmonitor.bat
-
Update flow.json aliases if needed
-
flow deploy project --network=testnet
-
Verify contracts are deployed https://testnet.flowscan.org/account/0xf8568211504c7dcf
-
Create a new email account for the storefront
-
Sign in to the dapp
-
Fund new storefront with some flow from the faucet https://testnet-faucet-v2.onflow.org/
-
Update all the js script imports for the coin/nftmarketplace contracts
-
Click the setup button for the storefront account
-
Mint a bunch of NFTs of different bronze coins, both heads and tails flow transactions send ./cadence/transactions/mint_nft.cdc 0x7b2848088d45b449 0 0 QmZrieu9iKvaSQjt9YksnkxKxghCeLPVubhAcjZovBPrio --signer=testnet-account --network=testnet
flow transactions send ./cadence/transactions/mint_nft.cdc 0x7b2848088d45b449 1 0 QmdKL3bdPWnh4M5HNsBoc9xTcTeUUiN4myUxmqKwVtnsL8 --signer=testnet-account --network=testnet
- As the storefront, list all the NFTs
Coin Coin.CollectionStoragePath = /storage/CoinCollection Coin.CollectionPublicPath = /public/CoinCollection Coin.MinterStoragePath = /storage/CoinMinter Coin.CollectionPrivatePath = /private/CoinCollection Coin.CoinFlipperStoragePath = /storage/CoinFlipper
NFTMarketplace /public/SaleCollection /storage/SaleCollection
Admin: 0xf8568211504c7dcf Storefront: 0x7b2848088d45b449
get_nft_ids.cdc
flow scripts execute ./cadence/scripts/get_nft_ids.cdc 0x7b2848088d45b449
flow scripts execute ./cadence/scripts/get_nft_ids.cdc 0x7b2848088d45b449 --network=testnet
get_collection_length.cdc
flow scripts execute ./cadence/scripts/get_collection_length.cdc 0x7b2848088d45b449
get_nft_details.cdc
flow scripts execute ./cadence/scripts/get_nft_details.cdc f8d6e0586b0a20c7
flow scripts execute ./cadence/scripts/get_nft_details.cdc 0xb5d3705b4021c2ea --network=testnet
get_nft_listings.cdc
flow scripts execute ./cadence/scripts/get_nft_listings.cdc 0x7b2848088d45b449
flow scripts execute ./cadence/scripts/get_nft_listings.cdc 0xb5d3705b4021c2ea --network=testnet
get_nft_item_full.cdc
flow scripts execute ./cadence/scripts/get_nft_item_full.cdc 0x7b2848088d45b449 0
get_metadata.cdc - Broken - To Fix
flow scripts execute ./cadence/scripts/get_metadata.cdc 0x7b2848088d45b449 0
check_coincollection.cdc
flow scripts execute ./cadence/scripts/check_coincollection.cdc 0x7b2848088d45b449
flow scripts execute ./cadence/scripts/check_coincollection.cdc 0x7b2848088d45b449 --network=testnet
Heads CID: QmZrieu9iKvaSQjt9YksnkxKxghCeLPVubhAcjZovBPrio Tails CID: QmdKL3bdPWnh4M5HNsBoc9xTcTeUUiN4myUxmqKwVtnsL8
setup_coin.cdc
flow transactions send ./cadence/transactions/setup_coin.cdc
flow transactions send ./cadence/transactions/setup_coin.cdc --signer=justin
flow transactions send ./cadence/transactions/setup_coin.cdc --signer=testnet-account --network=testnet
setup_coingame.cdc
flow transactions send ./cadence/transactions/setup_coingame.cdc
flow transactions send ./cadence/transactions/setup_coingame.cdc --signer=justin
mint_nft.cdc
flow transactions send ./cadence/transactions/mint_nft.cdc 0x7b2848088d45b449 0 0 QmZrieu9iKvaSQjt9YksnkxKxghCeLPVubhAcjZovBPrio --signer=testnet- account --network=testnet
flow transactions send ./cadence/transactions/mint_nft.cdc 0x7b2848088d45b449 1 0 QmdKL3bdPWnh4M5HNsBoc9xTcTeUUiN4myUxmqKwVtnsL8 --signer=testnet-account --network=testnet
play_game.cdc
flow transactions send ./cadence/transactions/play_game.cdc 0 0x7b2848088d45b449
flow transactions send ./cadence/transactions/play_game.cdc 0 0x7b2848088d45b449 --signer=justin
setup_sales.cdc
flow transactions send ./cadence/transactions/setup_sales.cdc
flow transactions send ./cadence/transactions/setup_sales.cdc --network=testnet --signer=testnet-account
flip_coin.cdc
flow transactions send ./cadence/transactions/flip_coin.cdc f8d6e0586b0a20c7 0
flow transactions send ./cadence/transactions/flip_coin.cdc f8d6e0586b0a20c7 0 --signer=justin
flow transactions send ./cadence/transactions/flip_coin.cdc 01cf0e2f2f715450 0
flow transactions send ./cadence/transactions/flip_coin.cdc 0x7b2848088d45b449 0 --network=testnet --signer=testnet-account
flip_coins.cdc
flow transactions send ./cadence/transactions/flip_coins.cdc
add_coingame.cdc
flow transactions send ./cadence/transactions/add_coingame.cdc 0 f8d6e0586b0a20c7
flow transactions send ./cadence/transactions/add_coingame.cdc 0 f8d6e0586b0a20c7 --signer=justin
remove_coingame.cdc
flow transactions send ./cadence/transactions/remove_coingame.cdc 0
flow transactions send ./cadence/transactions/remove_coingame.cdc 0 --signer=justin
list_for_sale.cdc
flow transactions send ./cadence/transactions/list_for_sale.cdc 0 1.0
flow transactions send ./cadence/transactions/list_for_sale.cdc 0 1.0 --signer=justin
flow transactions send ./cadence/transactions/list_for_sale.cdc 0 1.0 --signer=testnet-account --network=testnet
unlist_from_sale.cdc
flow transactions send ./cadence/transactions/unlist_from_sale.cdc 0
flow transactions send ./cadence/transactions/unlist_from_sale.cdc 0 --signer=justin
setup.cdc
flow transactions send ./cadence/transactions/setup.cdc
flow transactions send ./cadence/transactions/setup.cdc --signer=Alice
purchase.cdc
flow transactions send ./cadence/transactions/purchase.cdc f8d6e0586b0a20c7 0
flow transactions send ./cadence/transactions/purchase.cdc f8d6e0586b0a20c7 0 --signer=justin
send_coin.cdc
flow transactions send ./cadence/transactions/send_coin.cdc f8d6e0586b0a20c7 0 --signer=justin
flow transactions send ./cadence/transactions/send_coin.cdc 01cf0e2f2f715450 1
flow transactions send ./cadence/transactions/send_coin.cdc 0x7b2848088d45b449 1 --network=testnet --signer=testnet-account
Create emulator accounts
flow keys generate
flow accounts create --key PublicKey
then update the flow.json
fundEmulator.cdc
flow transactions send ./cadence/utilities/fundEmulator.cdc f8d6e0586b0a20c7 1000.0
flow transactions send ./cadence/utilities/fundEmulator.cdc 01cf0e2f2f715450 1000.0
getBalance.cdc
flow scripts execute ./cadence/utilities/get_balance.cdc f8d6e0586b0a20c7
flow scripts execute ./cadence/utilities/get_balance.cdc 01cf0e2f2f715450
I no longer use the instructions below, I instead just use this service for hosting the image and pinning it. https://app.pinata.cloud/
https://docs.ipfs.tech/how-to/command-line-quick-start/#take-your-node-online
Install and run 'ipfs init' ipfs daemon Goto localhost:5001/webui Add the files
Goto https://natoboram.gitlab.io/public-gateway-cacher/ Paste the CID into IPFS and click Cache and then wait
- Download visual code studio
- Sync settings
- Download git
- Install node https://nodejs.org/en/download/
- install react: npm install react-scripts npm start
- Clone this repo
- Install Flow CLI
- run 'npm install'
- run 'npm run start'