$12.12 -4.15%
LINK · 2w

Make a blockchain voting dApp with a Chainlink timer oracle

Many smart contracts on Ethereum require an external source of timing to trigger an on-chain action. For dApps using on-chain blockchain voting systems, this presents a challenge since voting windows are limited to a specific time. Without timers in Solidity, a voting smart contract would require some external source to modify the state of the voting window, open or closed.

On legacy systems, timing can be a simple task. System calls allow the time to be retrieved from the NTP synced OS time, there are hardware clocks and counters, and also sleep statements to halt code for a specified range of time. In Solidity smart contracts, events are triggered by off-chain transactions, which means Ethereum and other blockchains require an off-chain alarm clock to trigger events/function calls. Fortunately, Chainlink Nodes can act as a reliable alarm clock to trigger smart contracts.

Here we’ll show you how your dApp can implement simple time-gated voting, a process that’s becoming increasingly needed as more dApps move towards putting power in the users’ hands with DAOs. This setup includes the following:

Inheriting Chainlink functionality into your contract Formatting and submitting a Chainlink sleep (“until”) request Restricting vote starting to the contract owner Simple KYC to confirm each address only votes once Getters to check on vote status

You can find the code used in this demo on GitHub or use the easy to deploy Remix link.

Of course, this basic example is just the beginning. Any event you need to be triggered at a certain time can be handled with a Chainlink “until” request and this example can be used as a starting framework to build out your other time sensitive smart contracts.

Contract Definition and Constructor: pragma solidity ^0.6.6; import ""; contract ChainlinkTimedVote is ChainlinkClient { uint private oraclePayme...
Continue on
Recent news
No posts found