Fetch election calls with web3
If you want to connect to the AP Election results in JavaScript using web3, learn how here.
π Want a shortcut? π
Start with our boilerplate "Mission Control" App on GitHub. This shows how to connect to both mainnet and Kovan testnet using web3.
Walkthrough
Begin by installing web3
npm install web32. 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 and the kovan abi here)
// Mainnet
export const mainnetAddress = "0x0792724900B551d200D954a5Ed709d9514d73A9F";
export const mainnetContract = new web3.eth.Contract(abi, mainnetAddress);// Kovan
4. Fetch the election results!
// Mainnet
// Kovan
5. Make use of your verified election data!
You may find this screenshot from Remix easier to understand. This is example data returned for the state "TEST" in production.

6. Still having issues?
Learn more about Chainlink Oracles at https://docs.chain.link/docs
Tweet to @dawsonbotsford and @everipedia any engineering questions (or send a DM on Twitter to @dawsonbotsford)
Last updated
Was this helpful?