> 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-web3.md).

# Fetch election calls with web3

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

[**Start with our boilerplate "Mission Control" App on GitHub**](https://github.com/EveripediaNetwork/everipedia-ap-2020). This shows how to connect to both mainnet and Kovan testnet using web3.&#x20;

### Walkthrough&#x20;

1. Begin by installing web3

```
npm install web3
```

2\. Instantiate a web3 provider

```
const Web3 = require("web3");
export const web3 = new Web3(
  new Web3.providers.HttpProvider(
    "YOUR_INFURA_URL_OR_SIMILAR_PROVIDER"
  )
);
```

3\. Connect to the contract (the "abi" variable below is a JavaScript array. Find [the mainnet abi here](https://github.com/EveripediaNetwork/everipedia-ap-2020/blob/master/src/mainnet/election-contract.js) and the [kovan abi here](https://github.com/EveripediaNetwork/everipedia-ap-2020/blob/master/src/kovan/election-contract.js))

// Mainnet

```
export const mainnetAddress = "0x0792724900B551d200D954a5Ed709d9514d73A9F";
export const mainnetContract = new web3.eth.Contract(abi, mainnetAddress);
```

// Kovan

```
export const kovanAddress = "0x12B7B8Dea45AF31b6303E00C735332A8b6752856";
export const kovanContract = new web3.eth.Contract(abi, kovanAddress);
```

4\. Fetch the election results!

// Mainnet

```
const allWinners = await mainnetContract.methods
      .presidentialWinners(state)
      .call()
```

// Kovan

```
const allWinners = await kovanContract.methods
      .presidentialWinners(state)
      .call()
```

5\. Make use of your verified election data!

```
/** 
This is the shape of the data
{
  [state]: {
    winner: "Biden" | "Trump" | ...,
    resultNow: "1604003431", // string unix time that winner was called
    resultBlock: "11153856", // string etherum block where call was mined in
  }
}

you can find an array of all states (52 = 50 states + D.C. + US) here:
https://github.com/EveripediaNetwork/everipedia-ap-2020/blob/master/src/all-states.js
*/
```

You may find this screenshot from Remix easier to understand. This is example data returned for the state "TEST" in production.

![Function screenshot from remix.ethereum.org](/files/-MKvTIUP35LLH3eZgd4h)

6\. Still having issues?&#x20;

1. [Refer to our example repo](https://github.com/EveripediaNetwork/everipedia-ap-2020)
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))<br>


---

# 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-web3.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.
