> For the complete documentation index, see [llms.txt](https://connect.socios.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://connect.socios.com/partner-api/api-reference/polls-api/polls-api-endpoints.md).

# Polls API endpoints

The latest documentation for endpoint is always on the DevPortal: \
<https://partner.socios.com/devportal/apis/d93ca9b9-6e1f-4ec7-813e-a4e8c3c1d658/test>

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/polls" method="get" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% hint style="danger" %}
REMOVED WITH NO ALTERNATIVE AVAILABLE
{% endhint %}

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/poll/{pollId}" method="get" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/user/poll/{pollId}/vote" method="post" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% hint style="success" %}
:arrow\_down: **ALTERNATIVE: Allow a user to vote on a specific poll** :arrow\_down:
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```javascript
import { createWalletClient, privateKeyToAccount } from 'viem';

const privateKey = '0xSenderPrivateKey'; // Replace with the sender's private key
const account = privateKeyToAccount(privateKey);

const walletClient = createWalletClient({
  account,
  transport: http('https://rpc.ankr.com/chiliz'),
});

async function vote(id, weight) {
  const txHash = await walletClient.writeContract({
    address: '0xPollAddress', // Replace with the poll contract address
    abi: survey3ABI, // Poll contract ABI
    functionName: 'vote', // Function to cast the vote
    args: [id, BigInt(weight)], // Replace 'id' with answer id and 'weight' with the amount of tokens that should be used to cast the vote
  });
  return txHash;
}

// Example usage
vote('dab3d446-959f-47e7-8789-f618d969de1e', 1).then(console.log);
```

{% endcode %}

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/user/poll/{pollId}" method="get" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% hint style="success" %}
:arrow\_down: **ALTERNATIVE: Retrieve user vote on a specific poll** :arrow\_down:
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```javascript
import { createPublicClient, http, keccak256 } from 'viem';
import { abi as survey3ABI } from './Survey3ABI.json';

const client = createPublicClient({
  transport: http('https://rpc.ankr.com/chiliz'),
});

const pollAddress = '0xPollAddress'; // Replace with the actual poll contract address
const userAddress = '0xUserAddress'; // Replace with the user's wallet address

// Returns hashes of answerIds that the user voted on
async function getUserVoteHashes() {
  const votes = await client.readContract({
    address: pollAddress, // Poll contract address
    abi: survey3ABI, // Poll conttract ABI
    functionName: 'getUserAnswers', // Function to retrieve the answers that the user voted on
    args: [userAddress], // User's address whose votes you want to fetch
  });
  return votes;
}

// Returns votes in plain text
async function getUserVotesPlainText() {
  // fetch all answers
  const answers = await client.readContract({
    address: pollAddress, // Poll contract address
    abi: survey3ABI, // Poll conttract ABI
    functionName: 'getAnswers', // Function to retrieve the answers
    args: [], // User's address whose votes you want to fetch
  });

  // fetch user's votes
  const votes = await client.readContract({
    address: pollAddress, // Poll contract address
    abi: survey3ABI, // Poll conttract ABI
    functionName: 'getUserAnswers', // Function to retrieve the answers that the user voted on
    args: [userAddress], // User's address whose votes you want to fetch
  });

  // filter answers, return the ones that the user voted on
  const plainTextVotes = answers.filter(a => votes.includes(keccak256(a.id)));

  return plainTextVotes;
}

// Example usage
getUserVotesPlainText().then(console.log);
getUserVoteHashes().then(console.log);
```

{% endcode %}

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/user/polls" method="get" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% hint style="danger" %}
REMOVED WITH NO ALTERNATIVE AVAILABLE
{% endhint %}

{% openapi src="/files/Sjgt1g6TWcWhAHsAEnO3" path="/user/polls/history" method="get" %}
[Polls.json](https://31329255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMDcaoJLMj5Y3jzFMTONF%2Fuploads%2Fc4oidA5xBonCIsDYQArk%2FPolls.json?alt=media\&token=ef654fa4-42f8-4b36-9884-fdacf9eacf63)
{% endopenapi %}

{% hint style="danger" %}
REMOVED WITH NO ALTERNATIVE AVAILABLE
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://connect.socios.com/partner-api/api-reference/polls-api/polls-api-endpoints.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
