2

Working with the Chainlink Alarm Clock, my fulfill() method seems to never get called. So for the docs example (below), votingLive is never set back to false after time is up. Everything else works and I've gotten to this point with both rinkeby and kovan oracles in remix and locally all with the same issue.

Issue...

No time delay is being added, and function not executed.

Code...

pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";


contract ChainlinkTimedVote is ChainlinkClient
{
  uint private oraclePayment;
  address private oracle;
  bytes32 private jobId;
  uint private yesCount;
  uint private noCount;
  bool private votingLive;
  mapping(address => bool) public voters;

  //only the contract owner should be able to start voting
  address payable owner;
  modifier onlyOwner {
  require(msg.sender == owner);
  _;
  }

  constructor() public {
      setPublicChainlinkToken();
      owner = msg.sender;
      oraclePayment = 0.1 * 10 ** 18; // 0.1 LINK
      //Rinkeby alarm oracle
      oracle = 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e; 
      jobId = "4fff47c3982b4babba6a7dd694c9b204";
      //initialize votes
      yesCount = 0;
      noCount = 0;
      votingLive = false;
  }

  function startVote(uint voteMinutes) public onlyOwner {
      Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
      req.addUint("until", now + voteMinutes * 1 minutes);
      //Start voting window then submit request to sleep for $voteMinutes
      votingLive = true;
      sendChainlinkRequestTo(oracle, req, oraclePayment);
  }

  //Callback for startVote request
  function fulfill(bytes32 _requestId) public recordChainlinkFulfillment(_requestId) {
      //$voteMinutes minutes have elapsed, stop voting
      votingLive = false;
  }

  //Increments appropriate vote counter if voting is live
  function vote(bool voteCast) public {
    require(!voters[msg.sender], "already Voted!");
    //if voting is live and address hasn't voted yet, count vote  
      if(voteCast) {yesCount++;}
      if(!voteCast) {noCount++;}
      //address has voted, mark them as such
      voters[msg.sender] = true;
   }
   
   //Outputs current vote counts
  function getVotes() public view returns (uint yesVotes, uint noVotes) {
      return(yesCount, noCount);
  }
  
  function isVotingLive() public view returns (bool) {
      return votingLive;
  }

  //Lets user know if their vote has been counted
  function haveYouVoted() public view returns (bool) {
      return voters[msg.sender];
  }
}

Thoughts...

Maybe I'm building the request wrong?

      Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
      req.addUint("until", now + voteMinutes * 1 minutes);

Flipping

      votingLive = true;
      sendChainlinkRequestTo(oracle, req, oraclePayment);

to

      sendChainlinkRequestTo(oracle, req, oraclePayment);
      votingLive = true;

I'm also noticing no time delay is being added.

2
  • 1
    Clues: 1. Are you sure that your JOB is working correclty? 2. The Chainlink Oracles needs sometime to return the data. Maybe you need to wait the answer a little.
    – JR Grande
    Apr 1 at 10:10
  • Can you test this by setting votinglive to true first? Just to make sure that you are getting a response? Apr 1 at 15:55
3

It looks like there may be an issue with the nodes in the current Chainlink docs. Try this node (on Kovan) and job instead:

OracleAddress = 0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b

jobId = 982105d690504c5d9ce374d040c08654

For future reference, I searched similar jobs on market.link: https://market.link/search/all?network=42&search=Alarm%20Clock

The docs will be updated.

1
  • 1
    Was also working on this, and wasnt passing chainlink to the contract which was definitely causing some issues. Would be nice to also mention that in the docs for solidity newbies such as myself. Also fyi i was able to get the following oracle to work in Kovan ---- oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e; jobId = "a7ab70d561d34eb49e9b1612fd2e044b"; Apr 1 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.