Chainlink 101 Course

yes I have Go and ran export PATH=$GOPATH/bin:$PATH

1 Like

Ok, also have you completed the other steps? It could be hard to install a node if you dont know what you are doing.

Carlos Z

That works., thanks a lot !

1 Like

Thanks it is solved now

Hey @Patrick_Rotzetter, For me only the migration of MyContract.sol failed. All others were fine.
I could also get the ETH/USD price on the Kovan testnet.

Hereā€™s my error message. I reported that to Chainlink as well.

Starting migrations...
======================
> Network name:    'kovan'
> Network id:      42
> Block gas limit: 12487794 (0xbe8c72)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xa2b59300f37a1f1ccd7762d9f07462f168777aaa28b42745a511e5511f3512c4
   > Blocks: 1            Seconds: 4
   > contract address:    0x9dad33773D0da90cc02394070Ad0F3231Cb18c18
   > block number:        25921217
   > block timestamp:     1625470676
   > account:             0xaeE6b099f09142f95d0680C379c82C0A3D306a64
   > balance:             0.698866235
   > gas used:            226753 (0x375c1)
   > gas price:           5 gwei
   > value sent:          0 ETH
   > total cost:          0.001133765 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.001133765 ETH


2_mycontract_migration.js
=========================

   Deploying 'MyContract'
   ----------------------
   > transaction hash:    0xb839d55adcddb09a3e90d81fd4811514da29e990d1fa87ae9f85e494c4222257
   > Blocks: 2            Seconds: 8
   > contract address:    0x5c11a07b0165b714bAcd7db2cb17595d43163F22
   > block number:        25921223
   > block timestamp:     1625470700
   > account:             0xaeE6b099f09142f95d0680C379c82C0A3D306a64
   > balance:             0.690311785
   > gas used:            1665127 (0x196867)
   > gas price:           5 gwei
   > value sent:          0 ETH
   > total cost:          0.008325635 ETH


C:\Users\rapha\Documents\NFT\ETH201\ChainlinkTest\node_modules\request\request.js:816
          var e = new Error('ESOCKETTIMEDOUT')
                  ^
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: ESOCKETTIMEDOUT
    at ClientRequest.<anonymous> (C:\Users\rapha\Documents\NFT\ETH201\ChainlinkTest\node_modules\request\request.js:816:19)
    at Object.onceWrapper (node:events:513:28)
    at ClientRequest.emit (node:events:394:28)
    at TLSSocket.emitRequestTimeout (node:_http_client:761:9)
    at Object.onceWrapper (node:events:513:28)
    at TLSSocket.emit (node:events:406:35)
    at TLSSocket.Socket._onTimeout (node:net:475:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
    at PollingBlockTracker._performSync (C:\Users\rapha\Documents\NFT\ETH201\ChainlinkTest\node_modules\eth-block-tracker\src\polling.js:51:24)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
1 Like

Iā€™m having an issue when running the tests on Lottery.sol.
Running truffle test fails, and asks me to setProvider() before calling new.
Setting NODE_ENV to test doesnā€™t do any good.
Any ideas?

Iā€™m really lost here.

Contract: Lottery
    #requests a random number
      1) "before each" hook for "starts in closed state"


  0 passing (195ms)
  1 failing

  1) Contract: Lottery
       #requests a random number
         "before each" hook for "starts in closed state":
     Error: LinkToken error: Please call setProvider() first before calling new().
      at Object.checkProvider (node_modules\@truffle\contract\lib\utils\index.js:237:13)
      at Function.new (node_modules\@truffle\contract\lib\contract\constructorMethods.js:45:11)
      at Context.<anonymous> (test\LotteryTest-git.js:25:39)
      at processImmediate (internal/timers.js:439:21)
1 Like

Hey @raphbaph, hope you are ok.

Would be great to also check your project code, it might be a typo error or an await that you missed.

Please upload your projecto to a github repository so i can download it and replicate the issue :face_with_monocle:

Carlos Z

1 Like

Hey @thecil, thanks for taking a look. You can find the code here:
raphbaph/Lottery: Chainlink fueled ETH lottery with real-time USD based entry fee (github.com)

I have the suspicion that I need to downgrade HDWalletProvider. But not sureā€¦Would be immensely appreciated if you can take a look.

It could be, just install the HDwallet provider, i will still review your contracts and let you know :nerd_face:

Carlos Z

Hello, I have a question where is this _volume located or initialized in?

volume

1 Like

Its an argument for the fulfill function, which is used later in its logic.

Hope it helps, any other questions, let us know :nerd_face:

Carlos Z

1 Like

Thank you for the previous answer. :slight_smile:

I have another question on the lottery contract where does the player deposit the entrance fee into the contract?

Hi, I am having issues with the compiler, saying ^0.6.6 does not work, so I changed the solidity version to ^0.8.9 like recommended, but there is still an error. Can someone help?
Thank you, Brianna.

2021-09-29

2021-09-29updated

Hey @Bripeachy, hope you are well.

Could you please share your truffle.config file? which is the version specified in that one? should be at least the same than your contract.

Carlos Z

Hi Carlos (@thecil),

Iā€™m have one bug and one question:

The bug is this: Iā€™ve unboxed the chainlink examples via truffle, and Iā€™ve run npm install and installed hardhat, but when I try to run the tests I get the following error:

An unexpected error occurred:

ReferenceError: contract is not defined
    at Object.<anonymous> (/Users/richardjamieson/Documents/GitHub/chainlink_examples/test/MyContract_test.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/node_modules/mocha/lib/mocha.js:349:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/node_modules/mocha/lib/mocha.js:346:14)
    at Mocha.run (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/node_modules/mocha/lib/mocha.js:1006:10)
    at testFailures (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/builtin-tasks/test.ts:57:13)
    at new Promise (<anonymous>)
    at SimpleTaskDefinition.action (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/builtin-tasks/test.ts:56:32)
    at Environment._runTaskDefinition (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at SimpleTaskDefinition.action (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/builtin-tasks/test.ts:102:28)
    at Environment._runTaskDefinition (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at main (/Users/richardjamieson/Documents/GitHub/chainlink_examples/node_modules/hardhat/src/internal/cli/cli.ts:203:5)
(node:61729) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:61729) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
(node:61729) Warning: Accessing non-existent property 'VERSION' of module exports inside circular dependency

The part of the test code that this is referring to can be seen in this excerpt:

/* eslint-disable @typescript-eslint/no-var-requires */
const { oracle } = require('@chainlink/test-helpers')
const { expectRevert, time } = require('@openzeppelin/test-helpers')

contract('MyContract', accounts => {
  const { LinkToken } = require('@chainlink/contracts/truffle/v0.4/LinkToken')
  const { Oracle } = require('@chainlink/contracts/truffle/v0.6/Oracle')
  const MyContract = artifacts.require('MyContract')

  const defaultAccount = accounts[0]
  const oracleNode = accounts[1]
  const stranger = accounts[2]
  const consumer = accounts[3]

  // These parameters are used to validate the data was received
  // on the deployed oracle contract. The Job ID only represents
  // the type of data, but will not work on a public testnet.
  // For the latest JobIDs, visit a node listing service like:
  // https://market.link/
  const jobId = web3.utils.toHex('4c7b7ffb66b344fbaa64995af81e355a')
  const url =
    'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY'
  const path = 'USD'
  const times = 100

It seems that it doesnā€™t recognise the type ā€˜contractā€™ in line 5 - perhaps there is an extra import that I need in this file?

And then the second thing is a question: I am wanting to do an API call to the coinmarketcap API, and it requires a key. Do you know where in the chainlink contract I can put the key? Here is what the coinmarketcap docs say about using their API:

### Using Your API Key

You may use any  *server side*  programming language that can make HTTP requests to target the CoinMarketCap API. All requests should target domain  `https://pro-api.coinmarketcap.com` .

You can supply your API Key in REST API calls in one of two ways:
0)
1. Preferred method: Via a custom header named  `X-CMC_PRO_API_KEY`
2. Convenience method: Via a query string parameter named  `CMC_PRO_API_KEY`

So this is what Iā€™ve tried:

But doesnā€™t seem to be working yet. Iā€™ve also considered request.add(ā€œheadersā€, "ā€¦)

Any help much appreciated.

Thanks!
Richard

1 Like

Sorry, I have one more follow up question - I have got the chainlink API_consumer example contract working in remix on Kovan, but when I try to deploy it to either Binance Smart Chain or Binance Smart Chain Testnet, Iā€™m getting a deploy error - any idea why this might be?

Here is the error in remix:
Screenshot 2021-11-03 at 13.44.41

The only things Iā€™ve changed in the contract are the oracle and the job id. And my network settings for BSC and BSC testnet are good - Iā€™ve used them to deploy other contracts.

Any help much appreciated!

R

1 Like

Hey @RichJamo, hope you are well.

Now about the first post, are you trying it with hardhat? because it might require extra configuration that is not explained in the course (because the course was made with truffle).

Now the second issue with BSC, might be because the chainlink contract does not exist on that network, have you checked that? because remember that you are interacting with chainlink VRF through the address of that contract, which might not be the same in the BSC network.

Carlos Z

@thecil, Hi Carlos, Im in the Lottery part of course nad I am having an issue compiling, think you can take a look for me?

project:/contracts/Lottery.sol:31:15: TypeError: Type int_const 100000000000000000 is not implicitly convertible to expected type address.
        fee = 100000000000000000; // 0.1 LINK
              ^----------------^
,project:/contracts/Lottery.sol:79:29: TypeError: Wrong argument count for function call: 3 arguments given but expected 2.
        bytes32 requestId = requestRandomness(keyHash, fee, userProvidedSeed);
                            ^-----------------------------------------------^

hers my contract

pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";


contract Lottery is VRFConsumerBase, Ownable {
    using SafeMathChainlink for uint256;

    enum LOTTERY_STATE {OPEN,CLOSED,CALCULATING_WINNER}
    LOTTERY_STATE public lotteryState;
    AggregatorV3Interface internal ethUsdPriceFeed;
    uint256 public usdEntryFee;
    address payable[] public players;
    uint256 public randomness;
    address public fee;
    bytes32 public keyHash;
    event RequestedRandomness(bytes32 requestId);


    constructor(address _ethUsdPriceFeed, address _vrfCoordinator, address _link, bytes32 _keyHash) 
        VRFConsumerBase(
            _vrfCoordinator,
            _link
        )public {
        ethUsdPriceFeed = AggregatorV3Interface(_ethUsdPriceFeed);
        usdEntryFee = 50;
        lotteryState = LOTTERY_STATE.CLOSED;
        fee = 100000000000000000; // 0.1 LINK
        keyHash = _keyHash;

    }
    function enter() public payable {
        require(msg.value >= getEntranceFee(), "Not enough ETH to enter!");
        require(lotteryState == LOTTERY_STATE.OPEN);
        players.push(msg.sender);

    }
    function getEntranceFee() public view returns(uint256){
        uint256 precision = 1 * 10 ** 18;
        uint256 price = getLatestEthUsdPrice(); //8 decimals
        uint256 costToEnter = (precision / price) * (usdEntryFee * 10000000);
        return costToEnter;


    }
    function getLatestEthUsdPrice() public view returns (uint256){
         (
            uint80 roundID,
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound 
        ) = ethUsdPriceFeed.latestRoundData();
        return uint256(price);

    }

    //Access control functions

    function startLottery() public onlyOwner {
        require(lotteryState == LOTTERY_STATE.CLOSED, "Can't start a new lottery");
        lotteryState == LOTTERY_STATE.OPEN;
        randomness = 0;

    }

    function endLottery(uint256 userProvidedSeed) public onlyOwner{
        require(lotteryState == LOTTERY_STATE.OPEN, "Can't end lottery yet");
        lotteryState == LOTTERY_STATE.CALCULATING_WINNER;
        pickWinner(userProvidedSeed);


    }
    function pickWinner(uint256 userProvidedSeed) private returns(bytes32) {
        require(lotteryState == LOTTERY_STATE.CALCULATING_WINNER, "Needs to be calculating the winner!");
        bytes32 requestId = requestRandomness(keyHash, fee, userProvidedSeed);
        emit RequestedRandomness(requestId);

    }
    function fulfillRandomness(bytes32 requestId, uint256 randomness)internal override{
        require(randomness > 0, "random number not found");
        uint256 index = randomness % players.length;
        players[index].transfer(address(this).balance);
        players = new address payable[](0);
        lotteryState = LOTTERY_STATE.CLOSED;
        randomness = randomness;

    }
}

When I truffle compile, get this error, it was compiling just fine before requestId section of course.
Thank you.

1 Like

It means that the function requestRandomness() is expecting 2 arguments, instead of 3.

Check the contract VRFConsumerBase, code line 158.
located at: node_modules@chainlink\contracts\src\v0.6\VRFConsumerBase.sol

function requestRandomness(bytes32 _keyHash, uint256 _fee)

So you only have to send 2 arguments, the keyHash and fee, remove userProvidedSeed which is not need it anymore (its now located at code line 131 in the same VRF contract above).

Hope this helps. :nerd_face:

Carlos Z

This one, you just have a wrong variable type declaration.
At code line 31 you have: address public fee; instead of integer.

1 Like