Okay, I've been trying to learn the Hardhat environment, deploying and interacting with contracts I'm stuck and it's driving me nuts.


I'm practicing using the above contract, a contract that randomly sorts addresses that interact with the contract into Game of Thrones houses using Chainlink's VRF. Throwing this onto Remix, this works as intended. Deploying the contract and interacting on etherscan's site, it works fine, but I'm stumped on how to interact via a Hardhat environment.

// but useful for running the script in a standalone fashion through `node <script>`.
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
//const hre = require("hardhat");

const { ethers } = require("hardhat");
const { setupLoader } = require('@openzeppelin/contract-loader');

async function main() {
    // Hardhat always runs the compile task when running scripts with its command
    // line interface.
    // If this script is run directly using `node` you may want to call compile
    // manually to make sure everything is compiled
    // await hre.run('compile');
    const loader = setupLoader({ provider: web3 }).web3;
    var VRFAddress_Kovan = "0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9";
    var LinkTokenAddress_Kovan = "0xa36085F69e2889c224210F603D836748e7dC0088";
    //let fee = 0.1 * 10 ** 18
    //0.1 Link so 10^17, remember 1 ETH == 10^18 Wei
    // Link is divisible to 18 decimal places
    var keyhash = "0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4";
    let fee = web3.utils.toWei('0.1', 'ether');

    // We get the contract to deploy
    const DiceRoll = await hre.ethers.getContractFactory("VRFD20");
    const diceRoll = await DiceRoll.deploy(VRFAddress_Kovan, LinkTokenAddress_Kovan, keyhash, fee);

    await diceRoll.deployed();

    console.log("DiceRoll deployed to:", diceRoll.address);
    const [owner] = await ethers.getSigners();

    console.log("funding contract with Link")
    const LinkKovan = loader.fromArtifact('LINK', LinkTokenAddress_Kovan)

    LinkKovan.methods.transfer(diceRoll.address, 0.1).send({ from: owner })

    //LinkTokenAddress_Kovan.methods.transfer(diceRoll.address, 0.1).send({ from: owner })

    console.log("Rolling the dice with address:", owner.address);
    await diceRoll.rollDice(owner.address)
    //setTimeout(function () {
    //    console.log('after');
    //}, 50000); // 500 is 0.5 seconds
    //await diceRoll.house(owner.address);


// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
    .then(() => process.exit(0))
    .catch((error) => {

Right now, I'm getting the error:

Error: Could not find local build/contracts when looking for local artifacts

Which stems from line 39 where I attempt to load the Chainlink address so I can send tokens to my GoT House sorting contract, diceRoll.

const LinkKovan = loader.fromArtifact('LINK', LinkTokenAddress_Kovan)

What exactly am I doing wrong here? Is there any quick tutorial I can go to for learning hardhat? I learned Brownie first via's Patrick Collin's smartcontract course, I wish there was something as indepth equivalent for learning hardhat as lot of javascript tutorials keep bouncing between Truffle and hardhat and assume you're quite familiar with the packages beforehand.

  • Can you please add a screenshot of your directory? Nov 20, 2021 at 17:57

1 Answer 1


Suggest checking out the latest tutorial on Hardhat testing, which goes through the whole 'funding a contract with LINK' part. More specifically, you can see the completed repository here, with contracts, tasks to interact with the deployed contracts, and tests (including one that funds a contract with link). Hopefully that's enough to help you

Another relevant tutorial for deploying and interacting with contracts on hardhat is the hardhat tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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