Your Flow blockchain workflow is now complete with:
✅ Smart Contract (cadence/contracts/RoyaltyTracker.cdc)
✅ Transactions (4 transaction files in cadence/transactions/)
✅ Scripts (4 script files in cadence/scripts/)
✅ TypeScript Service (src/lib/flow-service.ts)
✅ React Hook (src/hooks/use-flow.ts)
✅ Example Component (src/components/dashboard/FlowWorkflowExample.tsx)
You can test the Flow workflow right now without deploying:
-
Use the Example Component:
// Add to any dashboard view import { FlowWorkflowExample } from "@/components/dashboard/FlowWorkflowExample"; // In your component: <FlowWorkflowExample />
-
Or Use the Hook Directly:
import { useFlow } from "@/hooks/use-flow"; const { initialize, addRoyaltyRecord, fetchRoyaltyRecords } = useFlow();
When you're ready to deploy to the actual Flow blockchain:
-
Install Flow CLI:
# Windows (PowerShell) iex "& { $(irm 'https://raw.githubusercontent.com/onflow/flow-cli/master/install.ps1') }"
-
Create Flow Account:
- Visit: https://testnet-faucet.onflow.org/
- Create a testnet account
- Save your private key securely
-
Configure Flow CLI:
flow init
-
Deploy Contract:
flow accounts add-contract RoyaltyTracker ./cadence/contracts/RoyaltyTracker.cdc --network=testnet
-
Update Contract Address: Edit
src/lib/flow-service.tsline 8:const CONTRACT_ADDRESSES = { RoyaltyTracker: "0xYOUR_DEPLOYED_ADDRESS", // Replace this };
Option A: Add to Existing View
Example: Add to DashboardOverview.tsx:
import { useFlow } from "@/hooks/use-flow";
import { useEffect, useState } from "react";
export function DashboardOverview() {
const { fetchRoyaltyRecords, isConnected } = useFlow();
const [totalRoyalties, setTotalRoyalties] = useState(0);
useEffect(() => {
const loadData = async () => {
if (isConnected) {
const records = await fetchRoyaltyRecords();
const total = records.reduce((sum, r) => sum + parseFloat(r.amount), 0);
setTotalRoyalties(total);
}
};
loadData();
}, [isConnected]);
return (
<div>
<h2>Total Royalties: {totalRoyalties} FLOW</h2>
{/* Rest of your component */}
</div>
);
}Option B: Create New View
Add a "Blockchain" view to your dashboard:
// In Dashboard.tsx
export type DashboardView =
| "overview"
| "analytics"
| "transactions"
| "splits"
| "notifications"
| "payouts"
| "blockchain"; // Add this
// In renderView():
case "blockchain":
return <FlowWorkflowExample />;Record Royalty:
const { addRoyaltyRecord } = useFlow();
const recordPayment = async (nftId: number, amount: number) => {
const result = await addRoyaltyRecord(
nftId,
amount,
userAddress,
"NBA Top Shot",
txHash
);
if (result.success) {
// Update UI
}
};Manage Splits:
const { addSplit, modifySplit } = useFlow();
// Create new split
await addSplit(nftId, addresses, percentages);
// Update existing split
await modifySplit(splitId, newAddresses, newPercentages);Query Data:
const { fetchRoyaltyRecords, fetchRoyaltySplits } = useFlow();
// Get all royalties
const records = await fetchRoyaltyRecords();
// Get all splits
const splits = await fetchRoyaltySplits();Before going to production:
- Connect Dapper Wallet successfully
- Initialize tracker (first time)
- Record a test royalty
- Create a test split (percentages sum to 100)
- Query royalty records
- Query royalty splits
- Update a split
- Verify all transactions on Flow Testnet explorer
await addRoyaltyRecord(
momentId,
royaltyAmount,
creatorAddress,
"NBA Top Shot",
transactionHash
);await addSplit(
nftId,
["0xCreator", "0xArtist", "0xDeveloper"],
[50.0, 30.0, 20.0]
);const records = await fetchRoyaltyRecords();
const totalEarned = records.reduce((sum, r) => sum + parseFloat(r.amount), 0);
const avgRoyalty = totalEarned / records.length;# 1. Start your dev server
npm run dev
# 2. Connect Dapper Wallet
# Click "Connect Wallet" in your app
# 3. Initialize (first time only)
# Use the FlowWorkflowExample component or call initialize()
# 4. Start using Flow functions
# Record royalties, create splits, query data
# 5. View on Flow Explorer
# Visit: https://testnet.flowscan.org/With this Flow workflow, you can:
- ✅ Track all royalty payments on-chain
- ✅ Manage royalty splits between collaborators
- ✅ Query historical royalty data
- ✅ Analyze earnings by NFT
- ✅ Verify all transactions on Flow blockchain
- ✅ Build transparent royalty distribution system
- Full Documentation: See
cadence/README.md - Contract Code: Check
cadence/contracts/RoyaltyTracker.cdc - Example Component: Study
src/components/dashboard/FlowWorkflowExample.tsx - Flow Docs: https://docs.onflow.org/
- Cadence Tutorials: https://docs.onflow.org/cadence/tutorial/01-first-steps/
Common issues and solutions:
"Wallet not connected" → Make sure Dapper Wallet is connected first
"Tracker not initialized"
→ Run initialize() once before using other functions
"Percentages don't sum to 100" → Ensure split percentages add up to exactly 100.0
"Transaction failed" → Check you have enough FLOW for gas fees
Your Flow blockchain workflow is fully set up and ready to use!
Start by:
- Running your app (
npm run dev) - Connecting your Dapper Wallet
- Opening the FlowWorkflowExample component
- Initializing your tracker
- Recording your first royalty!
Happy building! 🚀