Working with Polls
Prerequisite: Survey3ABI JSON file
Retrieve poll question
import { createPublicClient, http } from 'viem';
import survey3ABI from './survey3ABI.json';
const client = createPublicClient({
transport: http('YOUR-RPC.com'),
});
const pollAddress = '0xPollAddress'; // Replace with the actual poll contract address
// Returns question text
async function getQuestion() {
const question = await client.readContract({
address: pollAddress, // Poll contract address
abi: survey3ABI, // Poll conttract ABI
functionName: 'question', // Function to retrieve the question
args: [],
});
return question;
}
// Example usage
getQuestion().then(console.log);Retrieve poll answers
Allow a user to vote on a poll
Approve token staking
Prerequisite: erc20ABI JSON file
Vote on poll
Retrieve user vote on a poll
Last updated