Working with Polls
Prerequisite: Survey3ABI JSON file
Retrieve poll question
You can retrieve any poll question from Chiliz Chain, provided that you have the poll's contract address.
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
You can retrieve all poll answers from Chiliz Chain, provided that you have the poll's contract address.
Allow a user to vote on a poll
You can allow a logged-in user to vote a specific Socios.com poll.
We recommend to implement Reown's Wallet Kit (previously called WalletConnect) in order to have your users logged in via their web3 wallet. Once they are logged in, if they have a Fan Token of the team the poll belongs to, they will be able to vote on that poll.
We also recommend to check whether the user has a token or not before allowing them to vote, because if they don't, their vote will be rejected at the smart contract level.
Approve token staking
Prerequisite: erc20ABI JSON file
Vote on poll
Retrieve user vote on a poll
You can know whether a user has already voted on a specific poll or not, and if they have then you can retrieve which answer they have selected.
Last updated