📈
Everipedia
  • Home
  • Everipedia API
    • Everipedia.org REST API
  • Everipedia OraQles
    • About
    • Data Partners
      • Associated Press
  • Current OraQles Projects
    • January 5th, 2021 Senate Runoff
      • Ethers.js tutorial
      • Solidity Tutorial
  • Past OraQles Projects
    • 2020 US Presidential Election
      • 2020 US Presidential Election - Ethereum
        • Fetch election calls with Solidity
        • Fetch election calls with web3
        • Mainnet Oracle Data
        • Kovan Testnet Oracle Data
      • 2020 US Presidential Election - EOS
Powered by GitBook
On this page
  • 🚀 Want a shortcut? 🚀
  • Walkthrough

Was this helpful?

  1. Past OraQles Projects
  2. 2020 US Presidential Election
  3. 2020 US Presidential Election - Ethereum

Fetch election calls with Solidity

If you want to connect to the AP Election results in Solidity and deploy an Ethereum smart contract, learn how here.

Previous2020 US Presidential Election - EthereumNextFetch election calls with web3

Last updated 4 years ago

Was this helpful?

🚀 Want a shortcut? 🚀

.

Walkthrough

  1. Begin by starting a or using

  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.

6. Still having issues?

If you're using the above solidity code, you can

5. Fetch state data for any of all the states you are interested (52 states = 50 + D.C. + US).

Learn more about Chainlink Oracles at

Tweet to and any engineering questions (or send a DM on Twitter to )

Start with our boilerplate Solidity smart contract on GitHub
Truffle project
Remix
see here the "already declared states" (all Kovan test data)
See the exact list of states here.
Refer to our example repo
https://docs.chain.link/docs
@dawsonbotsford
@everipedia
@dawsonbotsford