PollD is a dApp that allows users to create polls with an unlimited amount of options to choose from. PollD only allows for a single option to be selected for each poll and a user (wallet) can only vote once.
To view the deployed contract, visit Etherscan (Sepolia).
You can interact with the PollDApp
smart contract using the following functions:
getPollCount()
: Returns the total amount of polls and the last PollID used.getPoll(uint)(PollDetails)
: Get relevant information of a Poll by its ID.
createPoll(string,string[])
: Creates a Poll given the question and an array of options to choose from.vote(uint256,uint256)
: Allows a user to vote given the PollID and the option index.
Structures
struct PollOption {
uint pollId;
uint optionIndex;
string title;
uint voteCount;
}
struct PollDetails {
uint id;
address creator;
string question;
uint expDate;
PollOption[] options;
}
To easily interact with PollD, you can use the make commands located in the Makefile.
You can also interact with the contract directly from Foundry. Those examples will be listed in dropdowns.
Foundryup must be running to build the project:
$ make start
In the root directory of the project, run the following command to compile the project:
$ make build
Build using Foundry
$ foundryup
$ forge build
$ make tests
Test using Foundry
$ forge test
$ make deploy
Deploy using Foundry
$ forge script script/DeployPollDApp.s.sol\
--rpc-url <RPC_URL>\
--broadcast\
--account <ERC_2335_KEY>\
--sender <WALLET_ADDRESS>
Create a local testnet node:
$ make local-chain
$ make get-poll-count
$ make get-poll
$ make create-poll
$ make vote
PollD creates a config file for storing both the contract_address
and rpc_url
which are fields required for most interactions with the dApp. If you need to clear the config, run the following command:
$ make clear-config
Interact using Foundry
$ anvil
$ cast send <CONTRACT_ADDRESS>\
"createPoll(string,string[])" "Favorite color?" "['red','blue','yellow']"\
--rpc-url <RPC_URL>\
--account <ERC_2335_KEY>
$ cast call <CONTRACT_ADDRESS>\
"getPoll(uint)(uint,address,string,uint)" 1
Create ERC-2335 Key
$ cast wallet import <KEY_NAME> --private-key <WALLET_PRIVATE_KEY>
To install Foundryup, run the following command in your terminal:
$ make install-foundry
OR
$ curl -L https://foundry.paradigm.xyz | bash