Working with Polls
Make sure to implement the prerequisite code, or else the examples in this page will not work!
Prerequisite: Survey3ABI JSON file
When working with polls, and for some use-cases (the ones that import survey3ABI), you will need the below survey3ABI.json file saved in your project folder.
Make sure that you import that file in your code in order to achieve the wanted step (the samples already have the necessary import code).
Retrieve poll question
You can retrieve any poll question from Chiliz Chain, provided that you have the poll's contract address.
Before you run this blockchain call, you need to know the poll's ID.
You can use the GET /polls/ endpoint to retrieve it. See this documentation.
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.
As of May 2025, you cannot retrieve poll answers media (such as pictures and videos) via this blockchain call.
To do that, you must use the Socios.com API GET /polls/ endpoint, documented here.
We are working on this for the next version of our survey smart contract. This is planned for end of 2025.
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
When approving token staking, you will need the below erc20ABI.json file saved in your project folder.
Make sure that you import that file in your code in order to achieve the wanted step (the samples already have the necessary import code).
Your private key must only be used in server-side code. DO NOT release code on production with your private key shared on front-end side code.
Vote on poll
This is a code-based alternative to the POST /poll/{pollId}/vote endpoint, which was deprecated from the Socios.com API in Q1 2025.
Your private key must only be used in server-side code. DO NOT release code on production with your private key shared on front-end side code.
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.
This is a code-based alternative to the GET /poll/{pollId} endpoint, which was deprecated from the Socios.com API in Q1 2025.
Last updated