Chainlink 101 Course

Can anyone get the test from this course to run ? having some issues with the test fixture

is the official code on github anywhere ? @PatrickAlphaC

1 Like

0 passing (452ms)
1 failing

  1. Contract: Lottery
    Request a random number
    “before each” hook for “starts in a closed state”:
    TypeError: Cannot read property ‘substring’ of undefined
    at Context. (test/Lottery_test.js:33:40)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
beforeEach(async() => {
            keyhash = '0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4'
            fee = '100000000000000000' //.1 eth
            seed = 123
            link = await LinkToken.new({from:defaultAccount})
            mockPriceFeed = await MockPriceFeed.new(8, price,{from:defaultAccount})
            vrfCoordinatorMock = await VRFCoordinatorMock.new(link.address,{from:defaultAccount} )

//this is line 33 that fails
            lottery = await Lottery.new(mockPriceFeed.address,vrfCoordinatorMock.address, link.address,keyHash,{from:defaultAccount})
            

        })

and this is my constructor:

pragma solidity ^0.6.6;

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

//theres a conflict between SafeMath and chainlink so we use SafeMathChainlink
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

/**
Chainlink VRF (Verifiable Random Function) is a provably-fair and verifiable source of randomness designed for smart contracts. Smart contract developers can use Chainlink VRF as a tamper-proof RNG to build reliable smart contracts for any applications which rely on unpredictable outcomes:

Blockchain games and NFTs
Random assignment of duties and resources (e.g. randomly assigning judges to cases)
Choosing a representative sample for consensus mechanisms
 */

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;

    address public recentWinner;

    uint256 public randomness;

    uint256 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; //50 dollars
        lotteryState = LOTTERY_STATE.CLOSED;
        fee = 100000000000000000 ;// 0.1 LINK

        keyHash = _keyHash;
    }
...
.


1 Like

ok figured it out… case typo… ‘keyhash’…

bloody javascript :frowning:

3 Likes

Can anyone let me know if you encountered the same issue when migrating the contracts

Starting migrations…

Network name: ‘kovan’
Network id: 42
Block gas limit: 12487794 (0xbe8c72)

1_initial_migration.js

Deploying ‘Migrations’

Error: *** Deployment Failed ***

“Migrations” – Invalid chain id…

2 Likes

Hey @Patrick_Rotzetter, hope you are great.

You might have to be more detailed so I can help you solve the issue.

First would be great to know which command are you running when your are migrating your contracts.
Also would be great to check your Migration files also.

please provide your code in the following method so i can test it properly:
https://forum.ivanontech.com/t/faq-how-to-post-code-in-the-forum/35357/2

Carlos Z

1 Like

There is nothing special about the code, I just used truffle unbox smartcontractkit/unbox then tried to migrate the contracts after having set MNEMONIC and RPC_URL

2 Likes

where did you set the MNEMONIC and RPC_URL? on the env file on truffle config?

From my experience, i had an issue with the env file, so my config have an option to set it from the env file or just manually.

const KOVAN_RPC_URL = process.env.KOVAN_RPC_URL || "https://eth-kovan.alchemyapi.io/v2/your-api-key"
const MNEMONIC = process.env.MNEMONIC || "your mnemonic"

Carlos Z

1 Like

Hi Carlos,

I added the url and mnemonic manually to my truffle-config.js file the way you showed me above but still getting the identical error as Patrick. It looks like this is an error from the HD-wallet. Do you know if any workaround?

https://github.com/trufflesuite/truffle/issues/3961

Thanks

1 Like

Hi all!

Getting the exact same error. I tried a few things such as adding the chain_id in the HDWalletProvider call but still errors out.
Works fine with ganache :(.

Been running into issues with the Truffle HDWallet since I started this course which is weird.

Thanks

1 Like

@Emmett, were you able to get the official code in github, and if so do you mind sharing the github repository with me. I tend to understand and visualise concepts better when I can read through the source code.

Hi All,

I tested adding the parameter “chainId” in the call to HDWalletProvider in the truffle-config.js after searching the github forums and found it worked:

    kovan: {
      provider: () => {
        return new HDWalletProvider({ mnemonic: mnemonic, providerOrUrl:url, chainId:42})
      },
      network_id: '42',
      skipDryRun: true
    },
  },

Hopefully that works for others.

Thanks!

3 Likes

Super helpful, thank you so much!

no I figured it out myself… which file do you need?

1 Like

@Emmett, Fantastic work. I’m still just exploring source codes to familiarize myself with the Chainlink Framework System. I have already reached out to https://chain.link/, and i’m in contact with some of their developers to see if they can provide me with the source code for the whole Framework.

@Emmett, https://blog.chain.link/starter-kit-showcase/

Hi guys,

I’m following instructions on running the chainlink node but running into errors. When I run the node with chainlink help I’m getting the error “bash: chainlink: command not found”. I’ve followed all previous instructions and not sure what the issue is. Anyone have any idea?

1 Like

This is the issue I’m having and have no idea how to fix this. This is after running make install
Screen Shot 2021-05-13 at 6.31.57 PM

1 Like

Hey @lohba, hope you are ok.

could you please specify which setup step are you going through?

I advice that installing a local node is quite complex and require a solid knowledge on many configuration tools to install it properly.

Also is not completely need it for the course, so dont take it to serious for the course, is only to learn how a node works.

Carlos Z

hey @thecil, thanks for getting back. I’m just going through the process of running a node here: https://github.com/smartcontractkit/chainlink

1 Like

have you already install the step 1?
You need to install and config properly each dependecy to make it run properly.

Install Go 1.15, and add your GOPATH’s bin directory to your PATH

Carlos Z.