Open dhruvkelawala opened 2 years ago
Yo man, I literally now See your Issue and I'm sending you an example of the code for a simple Starknet+React decentralized voting application( Following this General code Steps You can Solve Your problem) : Smart Contract (VotingContract.cairo): (#) VotingContract.cairo
var votes : map(eoa : felt) => felt
function init() -> pass
public function vote(candidate : felt) -> (): self.votes[eoa()] += candidate pass
public function getVotes() -> (votes : felt) : votes := self.votes[eoa()] React App Components (src/App.js): import React, { useState } from 'react'; import { StarkWareProvider } from '@starkware/starkware-provider';
function App() { const [candidate, setCandidate] = useState(0); const [voteStatus, setVoteStatus] = useState('');
const handleVote = async (starkProvider) => {
try {
const contract = starkProvider.getContract('
return (
<StarkWareProvider
starkEndpoint="
Voting App
{voteStatus}
); }
export default App;
Using this Codes, Be safe of :
Write the Cairo smart contract (VotingContract.cairo),compile the contract using the StarkWare compiler,deploy the compiled contract to the Starknet testnet,set up a React app with the @starkware/starkware-provider library,create a simple UI to allow users to vote for a candidate, connect the React app to the Starknet testnet by providing necessary StarkNet node endpoint, contract address, and key information and run the React app and interact with the Starknet-powered voting dApp.
Finalli replace placeholders like
Need to add an exampl dapp that shows how this library is used with Starknet + React