Javascript

錯誤:在尋找本地工件時找不到本地建構/契約,資助 chainlink VRF

  • November 20, 2021

好的,我一直在嘗試學習 Hardhat 環境,部署合約並與之互動我被卡住了,這讓我發瘋了。

https://docs.chain.link/docs/intermediates-tutorial/

我正在練習使用上述合約,該合約使用 Chainlink 的 VRF 將與合約互動的地址隨機排序到《權力的遊戲》房屋中。把它扔到 Remix 上,它按預期工作。部署合約並在 etherscan 的網站上進行互動,效果很好,但我對如何通過安全帽環境進行互動感到困惑。

// 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)
   console.log("Rolled!");
   //console.log('before');
   //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.
main()
   .then(() => process.exit(0))
   .catch((error) => {
       console.error(error);
       process.exit(1);
   });

現在,我收到錯誤:

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

這源於我嘗試載入 Chainlink 地址的第 39 行,以便我可以將代幣發送到我的 GoT House 排序合約 di​​ceRoll。

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

我在這裡到底做錯了什麼?有什麼快速教程可以讓我學習安全帽嗎?我首先通過 Patrick Collin 的 smartcontract 課程學習了 Brownie,我希望有一些與學習安全帽一樣深入的東西,因為許多 javascript 教程不斷在 Truffle 和安全帽之間跳來跳去,並假設你事先對這些包非常熟悉。

建議查看有關 Hardhat testing 的最新教程,該教程貫穿了整個“與 LINK 簽訂契約”部分。更具體地說,您可以在此處查看已完成的儲存庫,其中包含契約、與已部署契約互動的任務以及測試(包括通過連結為契約提供資金的測試)。希望這足以幫助你

另一個在安全帽上部署和與合約互動的相關教程是安全帽教程

引用自:https://ethereum.stackexchange.com/questions/113155