A simple on-chain voting system where users can vote for their favorite Darwin agents. Each vote is recorded on the Sui blockchain.
-
Move Smart Contract (
move/agent_votes/)sources/agent_votes.move- The voting logicMove.toml- Package configuration
-
Frontend Integration (
src/utils/suiClient.js)- Functions to vote and fetch vote counts
Just display vote counts without letting users vote:
// In Orchestration.jsx
import { getVoteCounts } from '../utils/suiClient';
import { useEffect, useState } from 'react';
const [voteCounts, setVoteCounts] = useState({});
useEffect(() => {
// Fetch votes every 10 seconds
const interval = setInterval(async () => {
const counts = await getVoteCounts();
setVoteCounts(counts);
}, 10000);
return () => clearInterval(interval);
}, []);
// Display in agent cards: "❤️ {voteCounts.speedrunner || 0} votes"To let users actually vote, you need to add a wallet connector:
- Install wallet adapter:
npm install @mysten/dapp-kit @mysten/wallet-standard @tanstack/react-query- Wrap your app in providers (in
main.jsxorApp.jsx):
import { SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
import { getFullnodeUrl } from '@mysten/sui/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import '@mysten/dapp-kit/dist/index.css';
const queryClient = new QueryClient();
const networks = {
testnet: { url: getFullnodeUrl('testnet') }
};
<QueryClientProvider client={queryClient}>
<SuiClientProvider networks={networks} defaultNetwork="testnet">
<WalletProvider>
<App />
</WalletProvider>
</SuiClientProvider>
</QueryClientProvider>- Add wallet connection button and voting:
import { useCurrentAccount, useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { voteForAgent } from '../utils/suiClient';
function AgentCard({ agentId }) {
const currentAccount = useCurrentAccount();
const { mutate: signAndExecute } = useSignAndExecuteTransaction();
const handleVote = async () => {
if (!currentAccount) {
alert('Please connect wallet first!');
return;
}
try {
await voteForAgent(agentId, { signAndExecuteTransactionBlock: signAndExecute });
alert('Vote recorded on-chain!');
} catch (error) {
console.error('Vote failed:', error);
}
};
return <button onClick={handleVote}>Vote</button>;
}-
Deploy the smart contract (see
move/agent_votes/README.md)- Build with
sui move build - Publish with
sui client publish --gas-budget 100000000 - Copy PackageID and RegistryID
- Build with
-
Update
src/utils/suiClient.jswith your deployed IDs -
Choose integration option (display-only or full wallet)
-
Test on testnet before going to mainnet
✅ Smart contract written ✅ Frontend utilities created ⏸️ Not deployed yet (waiting for you to deploy) ⏸️ Not integrated with UI (waiting for wallet setup)
You can develop the UI without deploying by just showing placeholder vote counts. When you're ready to go live:
- Install Sui CLI
- Deploy the contract
- Update the IDs
- Add wallet integration
- Users can vote!
The smart contract is super simple - just increments counters. No complex betting logic, just a like button that writes to blockchain 🔥