> For the complete documentation index, see [llms.txt](https://docs.everipedia.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.everipedia.org/past-oraqles-projects/2020-us-presidential-election/untitled/fetch-election-calls-with-solidity.md).

# Fetch election calls with Solidity

### 🚀  Want a shortcut? 🚀&#x20;

[**Start with our boilerplate Solidity smart contract on GitHub**](https://github.com/EveripediaNetwork/everipedia-ap-2020/blob/master/ethereum/contracts/TestnetConsumer.sol).&#x20;

### Walkthrough&#x20;

1. Begin by starting a [Truffle project ](https://www.trufflesuite.com/)or using [Remix](https://remix.ethereum.org/)
2. Set `pragma` and import the election results contract at the top of your smart contract

```
pragma solidity ^0.6.12;

import "https://raw.githubusercontent.com/EveripediaNetwork/everipedia-ap-2020/master/ethereum/contracts/TestnetConsumer.sol";
```

3\. Paste in this example code and change the `selectWinner` function to do what you need with the data!

```
contract FetchPresidentialWinners {
    struct Winner {
      string winner;
      uint256 resultNow;
      uint256 resultBlock;
    }
    
    ATestnetConsumer internal winners;
    
    constructor() public {
        // the deployed kovan test contract address
        winners = ATestnetConsumer(0x12B7B8Dea45AF31b6303E00C735332A8b6752856);
        
        // the deployed mainnet contract address
        // winners = ATestnetConsumer(0x0792724900B551d200D954a5Ed709d9514d73A9F);
    }
    
    
   function selectWinner(string memory _state) public view returns (string memory winner, uint256 resultNow, uint256 resultBlock)
  {
    (string memory winner, uint256 resultNow, uint256 resultBlock) = winners.presidentialWinners(_state);
    return (winner, resultNow, resultBlock);
  }
}
```

4\. Validate on kovan that you are getting what you expect from the `presidentialWinners` mapping.

If you're using the above solidity code, you can [see here the "already declared states" (all Kovan test data)](https://everipedia-ap-2020.vercel.app/kovan)

5\. Fetch state data for any of all the states you are interested (52 states = 50 + D.C. + US). [See the exact list of states here.](https://github.com/EveripediaNetwork/everipedia-ap-2020/blob/master/src/all-states.js)

6\. Still having issues?&#x20;

1. [Refer to our example repo](https://github.com/EveripediaNetwork/everipedia-ap-2020/tree/master/ethereum/contracts)
2. Learn more about Chainlink Oracles at <https://docs.chain.link/docs>
3. Tweet to [@dawsonbotsford](https://twitter.com/dawsonbotsford) and [@everipedia](https://twitter.com/Everipedia) any engineering questions (or send a DM on Twitter to [@dawsonbotsford](https://twitter.com/dawsonbotsford))


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.everipedia.org/past-oraqles-projects/2020-us-presidential-election/untitled/fetch-election-calls-with-solidity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
